Vijay Reddy
Vijay Reddy

Reputation: 53

cannot find module is the error if i try node hello.js

I am trying this command to run my js file to check whether node is installed properly or not: C:\Users\vijay reddy\hello.js

But I get this error:

Error: Cannot find module 'C:\Users\vijay reddy\hello.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

Upvotes: 2

Views: 4456

Answers (4)

Muthu Kumar
Muthu Kumar

Reputation: 480

module error for hello.js was occured due to filelname mismatch error.

Please check file name on both command & directory by running dir command in application directory.

dir

Common filename error was hello.js is saved as hello.js.txt because extensions are hidden by default in some OS. Make sure that preview extension was enabled in OS file manager.

Upvotes: 0

Kayvon Wallace
Kayvon Wallace

Reputation: 1

Error: Cannot find module 'C:\Users\vijay reddy\hello.js'

You wrote it was saved to the desktop, then this line should look like this

C:\Users\vijay reddy\Desktop>node hello.js

This most likely have something to do with you user inheritance level for your login to computer itself. It's stating you another path, try to save in Vijay reddy directly or make a guest name, that should always start in Document when using the cmd.

Upvotes: -2

Dhanushka N
Dhanushka N

Reputation: 190

May be my answer is not exactly relevant for this.But if you work on Windows OS and learning by creating manual files, another reason can be that windows saves files with the extension .txt. That means, if you create a file with mouse click-> create empty document and save as yourFileName.js, The OS saves as yourFileName.js.txt. So better to go the file's directory in command line and type dir and list down files. It will show all files clearly.

Upvotes: 0

Paul
Paul

Reputation: 36319

if you create a file hello.js like so:

console.log('Hello World!');

And you are in the directory it exists in, and run (from your command prompt):

node hello.js

You will get the correct output if node is installed correctly.

To figure out why it's not, try the other commands they suggest. If you try:

node -v

and you get nothing, or an error, then that means either Node isn't installed, or it's not in your current users %PATH%.

Also, depending on how you created hello.js, Windows may have "helpfully" changed it to hello.js.txt for you.

Upvotes: 3

Related Questions