-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (28 loc) · 773 Bytes
/
index.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
32
33
34
35
36
const http = require("http")
const hint = `
[
{
"topics ": ["NodeJs", "servers", "http module"]
},
{
"function ": {
"requests": "works with specific routes and methods",
"responds": "works with http status code"
}
}
]
`
const requestListener = function (req, res) {
if (req.url === "/" || req.url === "/text" ) {
res.setHeader("Content-Type", "text/html")
res.end("This is a simple text. Notice how it differs from others")
}
if (req.url === "/topic") {
res.setHeader("Content-Type", "application/json")
res.end(hint)
}
}
const server = http.createServer(requestListener)
server.listen(3000, () => {
console.log("This server works successfully")
})