Node download and install

1.node download and install

Download address: https://nodejs.org/en/download/
Insert image description here

2. Installation:

1. After downloading, double-click to open: continue

2. Click next to start the installation

3. Select the "Accept Button" to proceed to the next step

4. Select the installation path

5. Install the pattern you need

6. Start the installation install

7.Complete finish

After installation, open the terminal window+R

cmd and press Enter; enter the command: "node -v" to view the version number

If the version number appears, it means that you already have nodejs on your computer and the installation is successful!

3. Configure the environment

NodeJS and NPM cannot be used directly after they are installed. By default, the modules installed by NPM will not be installed in the NodeJS program directory. For example, the D drive we set during installation, "D:\Program Files\nodejs", When we use npm to install a cluster module, it will appear under the default path of the C drive. Therefore, if we do not modify the module installation directory of npm, then it will be installed here by default. As you test and develop various As more and more modules are installed in the project, the size of this folder will become larger and larger until it fills up your C drive. So we need to modify the npm configuration.

1. In the nodejs folder, create two folders: node_global; node_cecal.
This is used to store the cache file of the installation process and the final module configuration location.

2. Use the following commands to configure npm's global module directory and cache directory to the two directories we just created:
npm config set prefix "node_global file path"
npm config set cache "node_cache file path"
For example: npm config set prefix "D:\Program Files\nodejs\node_global"

3. Advanced system settings - environment variables
Additional: How to open environment variables
Add new system variables:
Fill in the variable name: NODE_PATH
variable value: D:\Program Files\nodejs\node_modules
Insert image description here

You also need to modify the default path of the nodejs file in the Path variable name.
Insert image description here

After the modification is completed, test:
enter the command: node and press Enter - then enter require('cluster') and
the following picture will appear, indicating success.
Insert image description here

4. Test installation

Enter the cmd command line window and enter node -v to view the nodejs version

node -v

npm -v view npm version

npm -v

5. Modify the module download path

The npm global module storage path and cache storage path are by default under the C drive "C:Users User AppData". In order to reduce disk memory usage, the download path and cache path need to be modified.
1

  1. In the nodejs installation directory, create two folders "node_global" and "node_cache"
    Insert image description here

  2. Modify the default folder
    and set the installation path of the global module to the "node_global" folder

npm config set prefix "D:\Program Files\nodejs\node_global"#文件夹绝对路径
npm config set cache "D:\Program Files\nodejs\node_cache"#文件夹绝对路径

Insert image description here
NOTE: If that fails, open a dos window with administrator rights

  1. Configure the environment variable of node_global to facilitate global module access through the command line
    D:\Program Files\nodejs\node_global

Insert image description here

  1. Installation test:
    Globally install the most commonly used express module for testing.
    Note that if an error is reported, please use administrator mode to open the cmd command window.
    Open the cmd command window.
npm install express -g
或者
npm install express --global #“-g”等同于“–global”,“-g” 是全局安装,不加“-g”就是默认下载到当前目录,“-g” 表示安装到之前设置的【node_global】目录下,同时nodejs会自动地在node_global文件夹下创建【node_modules】子文件夹。

Insert image description here
Insert image description here

6. Global configuration of Taobao mirror

Open the cmd command window, type node, press Enter
and then enter

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

Insert image description here

Install webpack globally

npm install webpack -g

Insert image description here

Guess you like

Origin blog.csdn.net/A_awen/article/details/121952701