1. Install NodeJS

Download address:

nodejs.cn/download/(Chinese address)

Nodejs.org/en/download…→ For example, download files:Nodejs.org/dist/v12.18…

Install after downloading, for example, the installation path is D:\Net_Program\Net_NodeJS

After the installation is complete, run CMD as the administrator and run the node -v and NPM -v commands respectively to view the version information

Note: The new version of Node.js has built-in NPM, which will be installed when installing Node.js. NPM is used to manage the packages node.js depends on, which can also be interpreted as installing/uninstalling node.js

Add the node_global and node_cache folders to the NodeJS installation directory. Run CMD as the administrator to locate the NodeJS installation directory. Then enter the following commands respectively:

npm config set prefix "D:\Net_Program\Net_NodeJS\node_global"
npm config set cache "D:\Net_Program\Net_NodeJS\node_cache"
Copy the code

Right – click computer, click Properties, click Advanced System Settings, click Environment Variables

System variable, new, variable nameNODE_PATH, the variable value isD:\Net_Program\Net_NodeJS\node_global\node_modules

The user variable, Path edit, willC:\Users\quber\AppData\Roaming\npmModified toD:\Net_Program\Net_NodeJS\node_global

System variable, Path edit, addD:\Net_Program\Net_NodeJS\node_globalIf it already exists, you do not need to add it



3, test,

Open CMD and type Node to enter development mode

You can type **console.log(‘Hello NodeJS! ‘)** Press Enter will display Hello NodeJS in the window

After the express module test configuration is complete, install a module test, install the most commonly used Express module, open the CMD window, locate the NodeJS installation directory, and enter the following command to install the module globally (after the installation is complete, We can see that there are dependency packages in the global folder node_global defined earlier) :

npm install express -g
Copy the code

-g stands for global installation



After installing the Express module, open a CMD window and navigate to the installation directory. Then type Node to enter the development mode. Then type **require(‘express’)** and press Enter

We can also create a js file to test the Express module. We can create a test.js file in the root directory of drive D with the following contents:

var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send("Hello World 8888 "); console.log("Hello World 8888 "); }); app.listen('8888'); console.log("nodejs start listen 8888 port!" );Copy the code

Then open the CMD window, navigate to the root directory of drive D, and enter the commandnode test.js“, and we type in the browserhttp://127.0.0.1:8888/ to see the output of the js file, and every time the browser refreshes, the CMD window will print Hello World 8888