1. Download the installation package
Visit address:
https://nodejs.org/en/download/
Choose the LTS version and choose the even-numbered NodeJS version, such as 8, 10, because the even-numbered version is a long-term stable version and has better compatibility. The NodeJS iteration version is too fast. It is no problem to choose an even version even if it is version 8.0. It is said that it usually takes up to 18 months to maintain and expand. The odd-numbered version number is said to be the development version before the even-numbered stable version.
Two, installation
- Double click to run the installation package
- Select the installation path, the default is C drive, I chose D drive here
- Default
Three, check the version
- Win + R, enter cmd, dos open command, the input
node -v
view the version number NodeJS
- Open the installation directory to view the folder
(the new version of Node.js already comes with npm, and it will be installed together when you install Node.js. The role of npm is to manage the packages that Node.js depends on, and it can also be understood as used to install/uninstall Node. .js needs to be installed)
Four, environment variable configuration
The environment configuration mainly configures the path of the global module installed by npm and the path of the cache cache. The reason for the configuration is that it will be similar in the future: npm install express [-g] (the optional parameters -g, g later) When the installation statement represents the meaning of global installation), the installed module will be installed in the path [C:\Users\Username\AppData\Roaming\npm], occupying the C drive space.
For example: I want to put the path of the full module and the cache path in the folder where I installed node.js, then create two folders [node_global] and [node_cache] under my installed folder [D:\nodejs] As shown below:
-
In the current folder, long press Shift + right mouse button to open the cmd command line
-
Enter the following command to set
npm config set prefix "D:\NodeJS\node_global" npm config set cache "D:\NodeJS\node_cache" 12
-
Set environment variables, close the cmd window, "My Computer"-right click-"Properties"-"Advanced System Settings"-"Advanced"-"Environment Variables"
-
Enter the environment variable dialog box, create a new [NODE_PATH] under [System Variables], enter it
D:\NodeJS\node_global\node_modules
, and modify the [Path] under [User Variables] toD:\NodeJS\node_global
Five, test
After the configuration, install a module to test, we install the most commonly used express module, open the cmd window,
enter the following command to install the module globally:
npm install express -g # -g是全局安装的意思