-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnode.js
More file actions
49 lines (48 loc) · 1.3 KB
/
node.js
File metadata and controls
49 lines (48 loc) · 1.3 KB
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
39
40
41
42
43
44
45
46
47
48
49
const http = require("http");
const fs = require("fs");
const url = require("url");
const figlet = require("figlet");
const server = http.createServer((req, res) => {
const page = url.parse(req.url).pathname;
console.log(page);
if (page == "/") {
fs.readFile("index.html", function (err, data) {
res.writeHead(200, { "Content-Type": "text/html" });
res.write(data);
res.end();
});
} else if (page == "/otherpage") {
fs.readFile("otherpage.html", function (err, data) {
res.writeHead(200, { "Content-Type": "text/html" });
res.write(data);
res.end();
});
} else if (page == "/index.css") {
fs.readFile("index.css", function (err, data) {
res.write(data);
res.end();
});
} else if (page == "/main.css") {
fs.readFile("main.css", function (err, data) {
res.write(data);
res.end();
});
} else if (page == "/main.js") {
fs.readFile("main.js", function (err, data) {
res.writeHead(200, { "Content-Type": "text/javascript" });
res.write(data);
res.end();
});
} else {
figlet("404!!", function (err, data) {
if (err) {
console.log("Something went wrong...");
console.dir(err);
return;
}
res.write(data);
res.end();
});
}
});
server.listen(8000);