Nodejs error: module.js: 340 throw err;

I tried to run the example server, but I got an error on Windows. Then I tried to run it on my friends machine but it went well too, windows system too. I do not know what's going on. Let me show you the source code and error message: source code:

var http = require("http");

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

      

output:

D:\test>node server.js

module.js:340
throw err;
^
Error: Cannot find module 'D:\test\server.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

      

Ps: server.js is the file to execute.

+3


source to share


2 answers


The error you mention appears because you are trying to execute a file that is not there.

Check if there is a file named server.js with the above code in the D: \ test folder .



I suggest you check if server.js is in your current folder from the console by typing the command dir

before going tonode server.js

+5


source


This problem happens because you have to check the execution path like

you need to go to D: / Drive and check if the test folder exists or not , if the file exists, then you should check if there is a .js server or not and you find there is no server.js in the test folder , why is this happening ...



so if you want to execute this script you need to go to where the file exists

0


source







All Articles