简体   繁体   中英

Install Node.js

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:

...

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).

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.

![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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM