-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (24 loc) · 906 Bytes
/
app.js
File metadata and controls
35 lines (24 loc) · 906 Bytes
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
const http = require('http');
const hostname = '127.0.0.1'; // Your server ip address
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
if (req.url == '/') { //check the URL of the current request
// set response content
res.write('<html><body><p>This is Home Page.</p></body></html>');
res.end();
}else if (req.url == "/admin") {
// set response content
res.write('<html><body><p color="red">This is Admin Page.</p></body></html>');
res.end();
}else{
// set Invalid response content
res.statusCode = 401;
res.end('Page Not Found');
}
console.log(`New request => http://${hostname}:${port}`+req.url);
});
server.listen(port, '0.0.0.0', () =>{
console.log(`Server running at http://${hostname}:${port}/`);
});