-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (26 loc) · 839 Bytes
/
server.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
const http = require("http");
const data = require("./data");
let fs = require("fs");
const PORT = 8000;
const requestListener = (req, res) => {
// res.writeHead(200, { "Content-Type": "text/html" });
// res.write("<h1>Welcome to vanilla node server</h1>");
// res.end();
// fs.readFile("./index.html", null, (error, data) => {
// if (error) {
// res.writeHead(404);
// res.write("Whoops! File not found!");
// } else {
// res.writeHead(200, { "Content-Type": "text/html" });
// res.write(data);
// }
// res.end();
// });
res.writeHead(200, { "Content-Type": "application/json" });
res.write(JSON.stringify(data));
res.end();
};
const server = http.createServer(requestListener);
server.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});