diff options
author | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2023-05-04 00:34:54 -0400 |
---|---|---|
committer | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2023-05-04 00:34:54 -0400 |
commit | 7bcd32a67804605c0d4322a9f9c8be4829dd5df7 (patch) | |
tree | ed1ec78357f0bdadac116b90b184670825f4e598 /practice/index.js | |
parent | 62215dfc4c2b8e96524057197c1e122b258d3cc2 (diff) |
fun with express
Diffstat (limited to 'practice/index.js')
-rw-r--r-- | practice/index.js | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/practice/index.js b/practice/index.js index c916bed..f121c37 100644 --- a/practice/index.js +++ b/practice/index.js @@ -1,8 +1,30 @@ -const http = require('http') +const express = require('express') +const app = express() -const app = http.createServer((request, response) => { - response.writeHead(200, { 'Content-Type': 'text/plain' }) - response.end('Habari Tanzania') +let notes = [ + { + id: 1, + content: "HTML is easy", + important: true + }, + { + id: 2, + content: "Browser can execute only JavaScript", + important: false + }, + { + id: 3, + content: "GET and POST are the most important methods of HTTP protocol", + important: true + } +] + +app.get('/', (request, response) => { + response.send('<h1>Habari Tanzania</h1>') +}) + +app.get('/api/notes', (request, response) => { + response.json(notes) }) const PORT = 3001 |