After downloading and installing NodeJS, the following files will be available under the path you have chosen:
By default, the NodeJS installation will install npm at the same time (module manager: modules used to manage user require, both global and local).
Note:
Global: Execute npm install <module name> -g will install the module in the global path. When the user requires (<module name>) in the program, he does not need to consider where the module is. If the global path is not modified, the module downloaded by the user will be under the path C:\Users\Administrator\AppData\Roaming\npm by default.
Local: Execute npm install <package name> (note that there is less -g) and install the module in the path currently pointed to by the dos window. At this time, other path projects cannot reference the module of this version!
Modify the default global path:
First configure the storage path of npm's global module (node_global) and the cache (global_cache). For example, I want to place the above two folders under %nodejs%\node_modules
1) Create two folders "node_global" and "node_cache" under D:\apps\nodejs\node_modules\.
2) Execute in the DOS window:
npm config set prefix “D:\apps\nodejs\node_modules\node_global” npm config set cache “D:\apps\nodejs\node_modules\node_cache”
If this method cannot be modified, it is OK:
Find node_modules\npm\.npmrc file in nodejs installation directory
Change as follows:
prefix = D:\apps\nodejs\node_modules\node_global cache = D:\apps\nodejs\node_modules\node_cache
3) At this time, the default global path installed by the npm module has been changed to the corresponding folder, but the user still cannot require these modules at this time, because the computer system does not know that you have changed the default path, so you need to open the settings dialog box in "win+R"-->"-->"Advanced"-->"Environment Variables".
4) The following are the most critical points (where you decide the success or failure of the modification!):
①First create a new variable in the "System Variables" and create a new variable named NODE_PATH. The variable value is: the absolute path to the node_modules folder in the folder newly created for storing the global module. (Tell the system that the user downloaded global module is here).
That is: D:\apps\nodejs\node_modules\node_global\node_modules
②After creating NODE_PATH, you need to tell the system the location of node and npm. At this time, you need to find the "Path" variable in the "System Variable" dialog box "Environment Variables".
Double-click to open it, add an English semicolon ";" at the end of the existing content, and then check whether there is any in the path.
D:\apps\nodejs\; (the address of node and npm)
The following article is to add if cnpm is installed:
D:\apps\nodejs\node_modules\node_global;
(cnpm path, npm install -g cnpm --registry=!!!)
The above module global installation path configuration method is all the content I share with you. I hope you can give you a reference and I hope you can support me more.