Install nodejs environment variable settings in windows and nodejs Environment Variables
You need to set two directories for adding node.exe to path2.C:\Program Files\nodejs
Add the environment variable NODE_PATH with the valueC:\Program Files\nodejs\node_modules
1. Download
Go to nodejs to download the node. msi installation package, which contains node. js and npm;
Double-click node. msi and select the installation path and npm;
Ii. Set Environment Variables
[No environment variables need to be designed for the new version, and the software will automatically write the environment variables]
Right-click a computer (or my computer) and choose Properties> advanced system Settings> environment variables.
Create a user variable.
Variable name: NODE_PATH
Value: C: \ Program Files \ nodejs \ node_modules
Note: The value is the nodejs installation directory.
Iii. Test
1. Write the test code test. js.
Find a project folder and create a new service folder. My directory is E: \ nodetest \ service.
Note: The path cannot contain Chinese characters.
Create a new UTF-8 code js file, file name casually, my file is called test. js
Add the following code to the js file:
var http=require('http');http.createServer(function (request,response){ response.writeHead(200,{'Content-Type':'text/plain'}) response.end("hello,world\n"); }).listen(8887); console.log('Server runing at http://127.0.0.1:8887');
2. Run
Start the nodejs service, press the window key + R, Enter cmd, and press Enter.
In the command line window, enter node E: \ nodetest \ service \ test. js
Note: No extra points are added at the end;
Successful
Enter http: // 127.0.0.1: 8887/in the browser and the result is as follows.