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.

Community
  • 1
  • 1
Mitul
  • 9,734
  • 4
  • 43
  • 60

1 Answers1

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

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
  • 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? – Mitul Jul 19 '11 at 03:08
  • 1
    PATH should contain the folder that has `node.exe`, this is what let's you run `node` form any folder – Pablo Fernandez Jul 19 '11 at 03:25