In this paper, starting from: y0ngb1n. Making. IO/a/b9f01718….

The preparatory work

Download the Latest LTS Version from the official download page. The Latest LTS Version: 10.14.1 is the Latest LTS Version from the official download page.

Enter the installation

For easy management, I created F:\ node.js \dev_tools\ Node \v10.14.1 to save the decompressed Node.js program, and installed NPM by default.

To use node.js commands in CMD, add “environment variables” :

Create environment variables for the Node.js installation pathNODE_HOME = F: \ Node. Js \ dev_tools \ Node \ v10.14.1Add to PathPath={... }; %NODE_HOME%;Copy the code

Since NPM is installed by default in Node.js, NPM commands can be used in global commands without additional configuration. If you want to use your own installed NPM, such as CNPM, you need to add the corresponding environment variables as above

test

Enter node -v and NPM -v in PowerShell:

PS C:\> node -v
v10.14.1
PS C:\> npm -v
6.4.1
Copy the code

You can see that the current installed versions of Node and NPM are v10.14.1 and 6.4.1 respectively.

NPM configuration

Viewing the Current Configuration

Use NPM config list for current configuration, or use NPM config ls -l for all configuration information.

Global module directory and cache directory

Configure the global module directory for the NPM installation, as well as the cache directory.

Why configure these two directories?

When executing a global install statement, such as:

npm install express -g
Copy the code
  • -gThis parameter is optional. -g indicates global installation

The express module will be installed in the {decompressed directory}\node_modules directory by default, such as F:\ node.js \dev_tools\ Node \v10.14.1\node_modules; NPM cache files will be stored in the C:\Users\%USERNAME%\AppData\Roaming\npm-cache directory. If the installation is based on the installation files directly, then both folders are in drive C by default, which will take up the space of our drive C.

Can you customize these two folders?

Next, configure the two directories, specifying “global module installation directory”, “cache directory” :

Configure the global module installation directory and save the file to the node_modules folder
npm config set prefix F: \ "Node. Js \ dev_tools \ Node \ v10.14.1"

Configure the cache directory
npm config set cache F: \ "Node. Js \ dev_tools \ Node \ v10.14.1 \ NPM - cache"

Verify that the configuration is successful
npm config list
# or
npm config ls -l
Copy the code

At this point, we perform the global installation of the Express module again, and you can see that the directory we specified appears.

Our custom configuration will be saved in the C:\Users\%USERNAME%\.npmrc file.

Configure the NPM image source

We can specify a mirror image of NPM source to achieve the effect of network speed, the default source is: https://registry.npmjs.org, access speed slower in the country.

At this point, we can use some excellent NPM image sources in China, such as:

  • CNPM:https://r.cnpmjs.org/
  • Taobao NPM mirror:https://registry.npm.taobao.org/

For the temporary use

npm --registry https://registry.npm.taobao.org install express -g
Copy the code

Permanent use

npm config set registry https://registry.npm.taobao.org

Verify that the configuration is successful
npm config get registry
# or
npm info express
Copy the code

Used through CNPM

npm install -g cnpm --registry=https://registry.npm.taobao.org

# use
cnpm install express -g

If you can't use CNPM, you may have specified the global module directory of NPM, so you need to configure the corresponding system environment
Copy the code
  • Note: in this case, the CNPM will also have the default configuration, which also needs to be carried out in the “NPM configuration” moduleGlobal module directoryThe cache directoryRelated Settings. Custom configurations are saved in theC:\Users\%USERNAME%\.cnpmrcFile.

The resources

  • Install Node.js and NPM
  • Node.js installation and configuration
  • Node.js Installation and Configuration (Windows)
  • Node.js installation and environment configuration for Windows
  • Install and configure Node.js in a Windows environment
  • Domestic excellent NPM image recommendation and use