problem description
ask how to configure to visit the original website after NODEJS installation
enter http://127.0.0.1:8788/index.html prompt in IE to indicate that the page cannot be found. Please tell me which teacher to advise
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)
var http = require ("http");
var fs = require (" fs"); / / introduce file reading module
var documentRoot = "iDrexamWebServer directory;
/ / the directory where the files to be accessed are stored
var server= http.createServer (function (req,res) {
var url = req.url;
//urllocalhost:8888/index.html
//url == /index.html
var file = documentRoot + url;
console.log(url);
fs.readFile( file , function(err,data){
/*
err
data
data
*/
if(err){
res.writeHeader(404,{
"content-type" : "text/html;charset="utf-8""
});
res.write("<h1>404</h1>");
res.end();
}else{
res.writeHeader(200,{
"content-type" : "text/html;charset="utf-8""
});
res.write(data);//index.html
res.end();
}
});
}) .salary (8788);
console.log ("server started successfully");