-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (29 loc) · 830 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
37
38
var http = require("http"),
path = require("path"),
fs = require("fs")
var server = http.createServer(function(request, response) {
if (request.url == "/") {
var htmlPath = path.join(__dirname, "index.html")
var htmlFileStream = fs.createReadStream(htmlPath)
response.writeHead(200, {
"Content-Type": "text/html"
})
htmlFileStream.pipe(response)
} else if (request.url == "/info.json") {
var responseObject = {
name: "Emma",
date: new Date().toJSON()
}
var responseJSON = JSON.stringify(responseObject)
response.writeHead(200, {
"Content-Type": "application/json"
})
response.write(responseJSON)
response.end()
} else {
response.writeHead(404, {})
response.write("File not found")
response.end()
}
})
server.listen(9090)