-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (31 loc) · 1.24 KB
/
app.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
// Import the built-in HTTP module from Node.js
const http = require("http");
// Create an HTTP server
const server = http.createServer(async (req, res) => {
// Check if the request is for the root URL ("/") and is a GET request
if (req.url === "/" && req.method === "GET") {
// Respond with a message if the root URL is accessed
res.write("Hello. I am here!");
res.end(); // End the response
}
// Check if the request is for the "/add" URL and is a GET request
else if (req.url === "/add" && req.method === "GET") {
// Respond with a message if the "/add" URL is accessed
res.write("Hello. I am add page!");
res.end(); // End the response
}
// Check if the request is for the "/admin" URL and is a GET request
else if (req.url === "/admin" && req.method === "GET") {
// Respond with a message if the "/admin" URL is accessed
res.write("Hello. I am admin page!");
res.end(); // End the response
} else {
// Respond with a message if the requested route is not defined
res.end("no route present ");
}
});
// Start the server and have it listen on port 3200
server.listen(3200, () => {
// Log a message to the console confirming the server is running
console.log("Server running at port 3200");
});