Install Node.js

Problem

I'm completely new to node.js. By reading the documentation and tutorials, I managed to download and install node.js on my windows.

How do I test it and make it work?

The file test.js is saved in the same directory as node.exe and contains:

console.log('Hello World');

Openning the command-line I typed:

$ node test.js

But nothing hapenns, just:

...
Problem courtesy of: Nuno Nogueira

Solution

![enter image description here][1]I have run it in nodejs shell and it is simply working

> console.log('Hello World');  
  Hello World  
  undefined  
>

Also I opened nodejs command prompt not default command prompt of windows and then

 node path_to_file 

it is working... same output

Solution courtesy of: Rajarshi Das

Discussion

Run the Node REPL by executing node via the command-line without any arguments. The reason you're not getting the expected results is probably because you're running node.exe directly. Since you're using windows, start up CMD and run node.exe from there. Once you have the REPL running, try node test.js again, and this time it will work.

Discussion courtesy of: shmuli

You are typing node test.js in the Node REPL not the command line. The ... is indicating that you haven't reached the end of a valid statement yet (because you are writing shell and not JavaScript).

Run a command line with your terminal emulator of choice (probably Windows Powershell if you are using Windows).

Discussion courtesy of: Quentin

This recipe can be found in it's original form on Stack Over Flow.