I think you are using node main.js not from the shell, but from node REPL .
You do not need to run node before.
$ cat main.js console.log("Hello, World!") $ node main.js Hello, World!
Hm, you are on Windows. Then you should do something like this in your cmd.exe:
c:\...> cd c:\projects\hello c:\...> type main.js console.log("Hello, World!") c:\...> node main.js Hello, World!
Note. The commands above cat and type are redundant and just to demonstrate the contents of the file.
Also, if you are inside nodejs REPL , you can write javascript code directly.
Just try:
> console.log('Hey'); 'Hey' undefined > require('./main.js'); Hello, World! undefined > exit Bye-bye
source share