This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (50 loc) · 1.58 KB
/
Copy pathserver.js
File metadata and controls
58 lines (50 loc) · 1.58 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
50
51
52
53
54
55
56
57
58
const {Console} = require ('console');
const fs = require('fs');
const htp = require('http');
const port = process.env.PORT || 3000;
// Author : CodzLab
// Js server req => res (v1.0)
const server = htp.createServer((req, res) => {
// res.statusCode = 200;
console.log(req.url);
res.setHeader('entent-type', 'text/html');
if (req.url=='/')
{
res.statusCode=200;
const land = fs.readFileSync('index.html');
res.end(land.toString());
}
else if (req.url=='/home')
{
res.statusCode=200;
const land = fs.readFileSync('index.html');
res.end(land.toString());
}
else if (req.url=='/blog')
{
res.statusCode=200;
const land = fs.readFileSync('src/blog.html');
res.end(land.toString());
}
else if (req.url=='/contact')
{
res.statusCode=200;
const land = fs.readFileSync('src/contact.html');
res.end(land.toString());
}
else if (req.url=='/about')
{
res.statusCode=200;
const land = fs.readFileSync('src/about.html');
res.end(land.toString());
}
// as above 'else if' statement, you can add according to your needation
else{
res.statusCode=404;
// const ntf = fs.readFileSync('404.html');
res.end(`</h1>Error 404 Not Found</h1><p>This is error 404 page or request not found on the website.</p>`)
}
});
server.listen(port, () => {
console.log(`Server running at ${port} port (http://localhost:${port}). Develope by Codzlab`);
});