-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl.js
More file actions
26 lines (25 loc) · 929 Bytes
/
url.js
File metadata and controls
26 lines (25 loc) · 929 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
const http= require("http"); //http module
const fs= require("fs"); //file system module
const myserver=http.createServer((req,res)=> {
const log=`${Date.now()}: ${req.url} New request received\n`
fs.appendFile('log.txt', log,(err, data)=> {
switch(req.url) {
case '/':
res.end("Home Page");
break;
case '/about':
const username=myurl.myquery.myname;
res.end(`About Page: Hello ${username}`);
break;
case '/search':
const search=myurl.myquery.mysearch;
res.end(`Search Page: You searched for ${search}`);
default:
res.end("404 Page Not Found");
}
//console.log("Request received from client");
//res.end("Hello hi")
});
});
//create server
myserver.listen(8000,() => console.log("Server Started"));