I installed nodejs in C:\Program Files (x86)\nodejs
then I created a .js file and saved it in my desktop just to output 'hello world' in the console:
console.log('hello world');
When I tried to run the file from the command prompt:
C:\Users\Laura>cd desktop
C:\Users\Laura\Desktop>node nodeTest.js
I get:
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\Laura\Desktop\testNode.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:901:3
I read many other related questions, and some of them recommend to run the install, and so I did.
C:\Users\Laura>npm install -g express
But no luck, still getting the same error message.
Make sure you saved the file as JavaScript. Un check 'Hide extensions for all known type' check box in Folder Options window will show you the correct file extension(Folder>>view>>Option).
I think the issue is the NODE_PATH environment variable. I had the same problem but once I issued (on Windows)
then all worked ok.
Cheers,
I faced the same problem. I just copied the testNode.js file(that contain the test code) and pasted into the root of nodejs directory manually. I tried this command
C:\Program Files (x86)\nodejs>node testnode.js
Bingo! I received this message.Then I typed this url in a browser and received the message "Hello World". Hope this help somebody.
You need to:
Hide extensions for known file types
from Windows Explorer folders optiontestNode.js.txt
.txt
so as the file to be resolved as JS fileThat's it, now it works!
Restart your command prompt and check your path variable (type: path). If you can't find find nodejs installation dir from output add it to the path variable and remember to restart cdm again...
I was having the same problem with a server someone had written a while back. It turns out I didn't have a few things installed that the script required.
This question was helpful to me.
I ended up being able to use:
Although in your instance it may just be a file that it doesn't have a path to. You could try putting that file in the same folder you are running the node script from.