-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_v1.js
31 lines (28 loc) · 879 Bytes
/
index_v1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const http = require('http')
let notes = [
{
id: 1,
content: "HTML is easy",
date: "2020-01-10T17:30:31.098Z",
important: true
},
{
id: 2,
content: "Browser can execute only Javascript",
date: "2020-01-10T18:39:34.091Z",
important: false
},
{
id: 3,
content: "GET and POST are the most important methods of HTTP protocol",
date: "2020-01-10T19:20:14.298Z",
important: true
}
]
const app = http.createServer((request, response) => {
response.writeHead(200, { 'Content-Type': 'application/json' })
response.end(JSON.stringify(notes)) // Muuttujassa notes oleva taulukko muutetaan JSON-muotoon metodilla
})
const PORT = 3001
app.listen(PORT)
console.log(`Server running on port ${PORT}`)