-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.js
More file actions
37 lines (36 loc) · 1.04 KB
/
http.js
File metadata and controls
37 lines (36 loc) · 1.04 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
const http = require("http");
const fs = require("fs");
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/html" });
if (req.url == "/user") {
if (req.method == "GET") {
res.write("<h1>User Fetched!!</h1>");
} else if (req.method == "POST") {
res.write("<h1>User Created!!</h1>");
} else if (req.method == "DELETE") {
res.write("<h1>User Deleted!!!</h1>");
}
res.end();
} else if (req.url == "/course") {
if (req.method == "GET") {
res.write("<h1>Course Fetched!!</h1>");
} else if (req.method == "POST") {
res.write("<h1>Course Created!!</h1>");
} else if (req.method == "DELETE") {
res.write("<h1>Course Deleted!!!</h1>");
}
res.end();
}
if (req.url == "/") {
fs.readFile("index.html", (err, data) => {
if (err) {
res.writeHead(400);
res.write("Error: Something unexpected!");
} else {
res.write(data);
}
res.end();
});
}
});
server.listen(3000, console.log("Server Started!..."));