npm modify the default installation path

This article is borrowed from: https://lvsige.blog.csdn.net/?t=1


Need to reinstall node:

1. It was installed to C:\Program Files by default before
2. There is Chinese in the node installation path

1. If the previously installed node is under Program Files, you need to uninstall the node first, and then install it to the specified directory of the node, and there can be no Chinese in the path; eg: C:\nodejs

It is also possible on the C drive, but don’t put it under Program Files. Create a new folder on the C drive: the nodejs
path is C:\nodejs (see picture)
Insert picture description here

2. After node is successfully installed, create two folders node_global and node_cache under C:\nodejs

Insert picture description here

3. Execute the configured command

npm config set prefix "C:\nodejs\node_gobal"
npm config set cache "C:\nodejs\node_cache"

Pressing the enter key will not display the change, see the figure below

Insert picture description here

4. Configure environment variables

①: Find the environment variable in the advanced system settings
Insert picture description here

②: Find Path for system variables
Insert picture description here
③: Double-click path, click New, add C:\nodejs C:\nodejs\node_gobal C:\nodejs\node_cache to the environment variable

Insert picture description here

④: Then keep clicking OK

5. npm config ls to view the configuration information of the global installation

If the red mark below appears, the modification is ok.
Insert picture description here

6, check whether the installation is successful, you can install express to check

Command: npm i express -g

Insert picture description here

Then express -v check the version number, and it will do.
Check the node_golbal folder,
there will be a node_modules package, which contains the express we just installed.

7. Install Taobao mirror

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

Insert picture description here

Cnpm appears in node_global.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45846359/article/details/110532013