Node.js download and installation and environment variable configuration (detailed tutorial)

Table of contents

1. Download the installation package from the official website address

 2. Installer

3. Environment configuration

 4. Test

 5. Install Taobao mirror image

5.1. Additional: If there is a problem, you can check whether your configuration is wrong


1. Download the installation package from the official website address

https://nodejs.org/zh-cn/download/

Select the node.js version corresponding to your project or system. I am using the latest version, Windows, 64-bit.

 If you want to download a specified version, click [Previous Versions] to select the version you want to download

 

 2. Installer

(1) After the download is complete, double-click the installation package to start installing Node.js

 (2) Click the [Next] button directly, here you can modify the installation path according to your personal needs, and continue to click the [Next] button after the modification

 (3) It can be done according to your own needs. Here I choose the default installation, and continue to click the [Next] button

 (4) Not selected, click the [Next] button directly

  (5) Click the [Install] button to install

 (6) After the installation is complete, click the [Finish] button

 

(7) To test whether the installation is successful, press the [win+R] key, enter cmd, and open the cmd window        

     Input: node -v // Display node.js version

                npm -v // display npm version

  --Successfully display the version description and install successfully

3. Environment configuration

(1) Find the installation directory, and create two new folders [node_global] and [node_cache] under the installation directory

 (2) After the creation is complete, open the cmd command window as an administrator (see Tips below for the opening method), and enter

 ①npm config set prefix "your path\node_global" (copy the "node_global" folder path you just created)

npm config set prefix "G:\node\nodejs\node_global"

②npm config set cache "your path\node_cache" (copy the "node_cache" folder path you just created)

npm config set cache "G:\node\nodejs\node_cache"

Tips: How to run cmd as an administrator: Click the [Start] menu in the lower left corner, enter " command prompt " in the search area, and then click [Run as administrator]

 =============== Or click the right mouse button and select [Run as Administrator] ========================= ===

 (3) Configure environment variables

 ①【This Computer】-Right click-【Properties】-【Advanced System Settings】-【Environment Variables】

 ② Click [New] in [System Variables]

 1) Variable name: NODE_PATH

Variable value: C:\Program Files\nodejs\node_global\node_modules

(The value of this variable is the location of your own installation file, modify the location information before node_global according to your storage location)

 Then you will find a [node_modules] folder in [node_global]

 

 Tips: If the [node_modules] folder is not automatically created after entering the variable value, manually create a [node_modules] folder under [node_global] , and then copy the path address of the [node_modules] folder you created to the variable value.

  ③ Edit [Path] in [User Variables]

  ④ Change the default [ ] under the C drive  AppData\Roaming\npm to [ ] node_global】的路径, and click OK

  ⑤ Select [Path] in [System Variables], click [Edit] to add [NODE_PATH], and then keep clicking [OK]

 

 4. Test

 After the configuration is complete, install one of the most commonly used express modules globally for testing

npm install express -g   // -g代表全局安装

 When the following interface appears, the configuration is successful

Tips: If the installation fails, it may be that you did not run the cmd window as an administrator, or you can modify the permissions of [node_global] and [node_cache]

Steps: Right-click the [node_global] folder, click [Properties], then click [Security], then click [Edit], check all the permissions, and then click [OK], and the steps for [node_cache] are the same.

 5. Install Taobao mirror image

①Install Taobao mirror image

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

  Check for success:

npm config get registry

  ②Install cnpm (on-demand installation)

Description: npm is the official package manager of node. cnpm is a Chinese version of npm, a custom cnpm (gzip compression support) command-line tool from Taobao instead of the default npm.

npm install -g cnpm --registry=https://registry.npmmirror.com

Check if the installation is successful

Command: cnpm -v

5.1. Additional: If there is a problem, you can check whether your configuration is wrong

①Open cmd and type the following command to check

 

③Open the installation directory and check whether there are the following folders

Check whether there is a folder named [node_modules] in [node_global]

⑤ The cnpm and express installed above will appear in the [node_modules] folder under [node_global]

Guess you like

Origin blog.csdn.net/qq_54247497/article/details/131657489