1. Install Node.js In Windows.
1.1 Install Node With Windows Installer.
- Go to Node.js download page to download the windows version to your local PC.
- 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.
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.
- Download it from https://nodejs.org/dist/v8.10.0/node-v8.10.0-win-x64.zip.
- Then unzip it to a local directory.
- Add the directory ( C:\WorkSpace\dev2qa.com\Tool\node-v7.10.1-win-x64 ) to system variable Path value.
- 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.
- Open windows file explorer.
- Right click your computer icon in left panel.
- Click Properties in popup menu list.
- Click Advanced system settings in the opened window.
- Click Environment Variables button in System Properties window.
- 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.
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.
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 >