1

In my earlier program, I had trouble in referencing hello.js file and run using node.js on windows. Please check this How to run a hello.js file in Node.js on windows?

setTimeout(function() 
{
console.log('world!');
},2000);
console.log('hello');

When I was at work place I was able to run the above program using the following syntax:

c:\>node c:\abc\hello.js

But when I came home and tried using the same syntax, the same program did not run. When I tried using the following syntax it worked. Why is this difference? Is this because of path variable or something else?

C:\>C:/njs/node.exe C:/njs/hello.js
hello
world!

Thanks in advance.

1 Answer 1

2

It seems that in the second computer, node is not on your PATH variable.

Please check this by doing:

echo %PATH%

from the command line.

If so you need to modify PATH and add node binaries there, see this link:

http://www.computerhope.com/issues/ch000549.htm

Sign up to request clarification or add additional context in comments.

2 Comments

So even if the path points to node.exe in a different folder (not containing the hello.js), then also it is valid as long as it points to one node.exe. Am I correct?
PATH should contain the folder that has node.exe, this is what let's you run node form any folder

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.