UNPKG

tatapower

Version:

This is my first module for tata power

40 lines (36 loc) 1.29 kB
let http = require("http"); let fs = require("fs"); let companyName = "Tata Power Ltd"; let server = http.createServer(function(req, res){ if(req.url=="/favicon.ico" ){ res.write(""); res.end(); }else if(req.url =="/"){ var htmldata = fs.readFileSync("./index.html"+req.url); res.writeHead(200, {"Content-Type":"text/html"}); let temphtml = htmldata.toString().replace("{{compname}}",companyName); res.write(temphtml); res.end(); }else{ fs.readFile("./"+req.url, function(err, data){ if(err){ res.writeHead(404, {"Content-Type":"text/html"}); res.write("<h1> No Donuts for you </h1>"); res.end(); }else{ res.writeHead(200, {"Content-Type":"text/html"}); data.toString().replace("{{compname}}","Hello There") let temphtml = data.toString().replace("{{compname}}",companyName); res.write(temphtml); res.end(); } }); } }); server.listen(4040, "localhost", function(err){ if(err){ console.log(err) }else{ console.log("server is now live on localhost:4040") } })