NPM global default installation path modification mode

Under normal circumstances, we installed Node.jsenvironment, the program will automatically NPMroute the global module settings in the system tray (usually the Clower plate), we do not recommend global path settings in the system tray in the project development phase, it will not only affect your PC's performance, but also very safe. You can set the default download path of the global directory with the following command:

Enter the command, view the current configuration:

npm config ls

The result:
Here Insert Picture Description
The first time you use NPMthe installation package, it will only be seen in the configuration prefixoption is the NPMdefault global installation directory. However, if multi-use NPMinstallation package, we would see cacheand prefixtwo paths, as shown below:
Here Insert Picture Description
The first step:

Create two folders in the directory to be changed, namely: node_global_modulesand node_cache, the effect is as:
Here Insert Picture Description

Step two:

Open a command prompt, execute the following two commands:

npm  config set prefix "D:\dev\nodejs\node_modules\npm\node_global_modules"
npm  config set cache "D:\dev\nodejs\node_modules\npm\node_cache"

After successful execution, you can npm config lsview the result of the configuration command, as shown in FIG effect:
Here Insert Picture Description
Step:

After verifying successful configuration, you need to configure the environment variables. In the environment variables, a new system variable, the variable name: NODE_HOMEvariable values: D:\dev\nodejsresults shown in Figure:
Here Insert Picture Description
the Pathvariable names, the new variable values:

%NODE_HOME%
%NOED_HOME%\node_modules
%NODE_HOME%\node_modules\npm\node_global_modules\

Results shown in Figure:
Here Insert Picture Description
After saving, you can re-execute the command to install the global view NPMdependencies in the global default installation directory is configured directory for us, if successfully downloaded to the directory after setting successfully modified the global default installation path.

Published 124 original articles · won praise 9 · views 20000 +

Guess you like

Origin blog.csdn.net/p445098355/article/details/104525919