How To Install Node JS In Windows

Node.js is a javascript runtime environment. It encapsulate google Chrome V8 engine and optimizes some special use cases and provides alternative API that makes V8 engine execute better in a non browser environment. It is single thread, event driven and none block IO, all these character make it runs very fast and efficiency. This article will tell you how to install it in Windows and how to write the hello world example use it.

1. Install Node.js In Windows.

1.1 Install Node With Windows Installer.

  1. Go to Node.js download page to download the windows version to your local PC.
  2. Double click the installer file to start the installation. The process is simple and clear, just click Next button until finish. But remember Node.js installed directory during the installation.
    install node.js in windows directory

1.2 Install Node With Windows Binary.

Beside use windows installer, you can also install node with binary file which is compressed in a zip format file.

  1. Download it from https://nodejs.org/dist/v8.10.0/node-v8.10.0-win-x64.zip.
  2. Then unzip it to a local directory.
  3. Add the directory ( C:\WorkSpace\dev2qa.com\Tool\node-v7.10.1-win-x64 ) to system variable Path value.
  4. Open dos command window, run node -v to verify that the installation is successful.

2. Verify Node.js Installation.

2.1 Verify Node.

Now Node.js has been installed in windows, you can run below command in a dos window to test whether it is installed successfully or not.

C:\Users\Jerry>node --version
v8.10.0

If the output is the correct Node.js version that you installed, that means you installed successfully.

If you meet errors such as ‘node is not recognized as an internal or external command, operable program or batch file‘, that means node.exe can not be find in executable program path. You just need to add Node.js installation directory( C:\Program Files\nodejs ) in the Path system variable value as below.

  1. Open windows file explorer.
  2. Right click your computer icon in left panel.
  3. Click Properties in popup menu list.
  4. Click Advanced system settings in the opened window.
  5. Click Environment Variables button in System Properties window.
  6. In the System variables area, find the Path variable and add Node.js installation directory at the end of it’s value. Do not forget add semicolon ( ; ) before the directory value.
READ :   Node JS Event Loop And Custom Event Example

add node.js install directory in path system environment variable value

After above settings, open a new dos terminal and run command path in it, you should see the Node.js installation directory in the value.

2.2 Verify NPM.

NPM is the abbreviation of node package manager, it is installed during Node.js installation also. Run below command in a dos terminal to check it’s installation status. If output the correct version number means it is installed correctly.

C:\Users\Jerry>npm --version
5.6.0

3. Write And Execute The First Node.js Script.

Now you can write your first Node.js script file. I recommend you use sublimetext as the JavaScript editor, it is simple and easy to use. You can also use Eclipse, Android Studio etc that you are familiar with.

Just write below JavaScript code in a file saved as hello_node.js.

console.log('Hello Node.js!');

Cd to the js file saved directory and execute node hello_node.js in dos terminal, then you can see Hello Node.js! is printed.

4. Execute Node Script In Node Shell.

Besides run java script file through node command, you can also use node shell to execute node command.

Open a dos terminal, input node in the command line. Then input console.log(‘Hello World’); , click enter. You can see output as below.

C:\>node
> console.log('Hello World');
Hello World
undefined
>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.