How to execute a hello world javascript file in node.js

looks like you are in a node console already. you typed node which correctly started node (so your path is fine). Now you are telling node to interpret

node C:\Users\Ankur\Downloads\NodeJS\working\hello_world.js

as javascript which it doesn't like.

You should be able to type console.log('hello world'); here and see it appear.

To run your file, quit out of the node interpreter (i think control-X, maybe control-C), and at your C:> prompt, THEN type

node C:\Users\Ankur\Downloads\NodeJS\working\hello_world.js

Alternately,

cd C:\Users\Ankur\Downloads\NodeJS\working\
node hello_world.js

Use Node.js command prompt, then type in node C:\Users\Ankur\Downloads\NodeJS\working\hello_world.js


You have entered the node console, by typing node into a command prompt, and then tried to execute node from within itself. Just type node c:\etc\...\ from the command prompt, not the node shell.

Press: [Start]->[Run]->[c][m][d]

And enter command: node C:\Users\Ankur\Downloads\NodeJS\working\hello_world.js

Alternatively, use sublime editor, and install a node js build system, and just open the file you want to run, and press the build shortcut, getting the output in the console.