UNPKG

bhargav

Version:

fje 'nkijnge[o

32 lines (30 loc) 863 B
var http=require('http'); var fs=require('fs') console.log("starting"); var config= JSON.parse(fs.readFileSync("config.json")); var host=config.host; var port = config.port; var server=http.createServer(function(request,response){ console.log("Received request: "+request.url); fs.readFile("./public"+request.url, function(error, data){ if(error){ response.writeHead(404, {"Content-type":"text/plain"}); response.end("Sorry page was not found");} else{ response.writeHead(200, {"Content-type":"text/html"}); response.end(data); } }) }); server.listen(port, host,function(){ console.log("listening"+host+":"+port); }); fs.watchFile("config.json",function(){ config=JSON.parse(fs.readFileSync("config.json")); host=config.host; port=config.port; server.close(); server.listen(port, host,function(){ console.log(" Changed, Now listening"+host+":"+port); }); });