-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.js
More file actions
41 lines (37 loc) · 1.04 KB
/
http.js
File metadata and controls
41 lines (37 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
38
39
40
41
const http=require('http');
// Hyper Text Transfer Protocol
const fs=require('fs');
// http.createServer(Routing).listen(Port);
// createServer((request,response)=>{})
http.createServer((req,res)=>{
// Output
// res.write('Hello World !! How are you ??');
// res.end();
// console.log(req.url);
// Routing
if(req.url=='/'){
// res.write('Hello I am Index Page');
// res.end();
fs.readFile('index.html','utf-8',(err,data)=>{
res.write(data);
res.end();
});
}
else if(req.url=='/about'){
// res.write('<h1>About Us</h1><p>This is about us</p>');
// res.end();
fs.readFile('about.html','utf-8',(err,data)=>{
res.write(data);
res.end();
});
}
else{
// 404 Page
res.write('404 Page not Found :|');
res.end();
}
}).listen(8080,(err)=>{
console.log('Server Start !');
});
// port - 1025 - 9999 -> 3000(react) -> 8080/8000 Node
// Server close in terminal -> CTRL + c