-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (27 loc) · 851 Bytes
/
server.js
File metadata and controls
30 lines (27 loc) · 851 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
const http = require('http');
const fs = require('fs');
const hostname = '127.0.0.1';
const port = 3000;
const home = fs.readFileSync('./home.html');
const about = fs.readFileSync('./about.html');
const services = fs.readFileSync('./services.html');
const contact = fs.readFileSync('./contact.html');
const server = http.createServer((req, res)=>{
console.log(req.url);
let url = req.url;
res.writeHead(200, {'Content-type':'text/html'});
if(url == '/' || url == '/home'){
res.end(home);
}else if(url == '/about'){
res.end(about);
}else if(url == '/services'){
res.end(services)
}else if(url == '/contact'){
res.end(contact);
}else{
res.end('404 page not found');
}
})
server.listen(port, hostname, ()=>{
console.log(`Server started at http://${hostname}:${port}`);
})