const http = require("http");
const fs = require("fs");
function startServer(){
let create = function (req, res){
if (req.url === "/" || req.url === "/home" ){
res.writeHead(200,{"Content-Type":'text/html'});
fs.createReadStream(__dirname+"/Hello.html",'utf8').pipe(res);
}else if (req.url === "/index"){
res.writeHead(200,{"Content-Type":'text/html'});
fs.createReadStream(__dirname+"/Index.html",'utf8').pipe(res);
}else if (req.url === "/json"){
res.writeHead(200,{"Content-Type":'application/json'});
const json = {
name:"king",
age:34
}
res.end(JSON.stringify(json));
}else{
res.writeHead(404,{"Content-Type":'text/html'});
fs.createReadStream(__dirname+"/404.html",'utf8').pipe(res);
}
}
let server = http.createServer(create);
server.listen(3000,'127.0.0.1');
console.log("server started on localhost port 3000");
}
exports.startServer = startServer;
startServer();