Here is my Javascript code...
var http = require ('http');
var fs = require('fs');
var port = '2405';
function send404Response(response){
response.writeHead(404, {"Content_Type": "text/plain"});
response.write("Error 404: Page not found!");
response.end();
}
function onRequest(request,response){
if(request.method == 'GET' && request.url == '/'){
response.writeHead(200, {"Content-Type": "text/html"});
fs.createReadStream("./index.html").pipe(response);
} else{
send404Response(response);
}
}
http.createServer(onRequest).listen(port);
console.log("Server is now running...");
When I write node /Users/SurajDayal/Documents/ass2/app.js in terminal and go to http://localhost:2405/ the terminal gives the error....
events.js:160 throw er; // Unhandled 'error' event ^
Error: ENOENT: no such file or directory, open './index.html' at Error (native)
Directory structure: