This article was reproduced from: http://www.cnblogs.com/fisheleven/p/6775380.html?utm_source=itdadao&utm_medium=referral
Citation: After installing Nodejs, the global module via NPM is installed by default to ROAMING\NPM under {%userdata%}c:\users\username\appdata\, which is certainly not the right default.
1, install the LTS version of Nodejs, this article is v6.10.2 (includes NPM 3.10.10). The Msi,nodejs installation path is automatically added to the PATH environment variable;
The installation path for this article is: D:\Program Files\nodejs
After the modification is complete:
2, create a new folder under the Nodejs installation path Node_cache is used to store the cache of the download package; that is: D:\Program Files\nodejs\node_cache;
3, run the npm config set cache "D:\Program Files\nodejs\node_cache" to set the caching folder;
Run npm config set prefix "D:\Program Files\nodejs" to set the global module storage path;
Note: Nodejs will automatically look for the path under the path to the Node_modules folder to actually store the global module, which is why prefix is not called global;
Later installed global modules will be placed under D:\Program files\nodejs\node_modules, with NPM module in a folder;
4, modify the D:\Program FILES\NODEJS\NODE_MODULES\NPM\NPMRC file and change the default value to:
Prefix=d:\program Files\nodejs, if you do not make this modification, NPM will still use the default path to find the installed global module when running NPM ls-g;
5, run npm install express-g Global Installation Express module, can be found in D:\Program Files\nodejs\node_modules under the Express folder;
6. Run npm list-g , listing all global modules:
D:\Program Files\nodejs
+--[email protected]
| +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| '---[email protected]
'---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
| '---[email protected]
| '---[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
| '---[email protected]
| '---[email protected]
| +--[email protected]
| '---[email protected]
+--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| | +--[email protected]
| | '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
| +--[email protected]
| | '---[email protected]
| | +--[email protected]
| | '---[email protected]
| +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | +--[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | | +--[email protected]
| | | | | '---[email protected]
| | | | '---[email protected]
| | | | '---[email protected]
| | | '---[email protected]
| | '---[email protected]
| '---[email protected]
| '---[email protected]
| +--[email protected]
| | '---[email protected]
| '---[email protected]
| +--[email protected]
| '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| +--Concat-[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | +--[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | | +--[email protected]
| | | | | '---[email protected]
| | | | '---[email protected]
| | | | '---[email protected]
| | | '---[email protected]
| | '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | | '---[email protected]
| | | '---[email protected]
| | | '---[email protected]
| | '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
| +--[email protected]
| | +--[email protected]
| | | '---[email protected]
| | | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| '---[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | '---[email protected]
| | +--[email protected]
| | | '---[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | | '---[email protected]
| | | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| | '---[email protected]
| +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | '---[email protected]
| +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | | +--[email protected]
| | | +--[email protected]
| | | '---[email protected]
| | '---[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| | '---[email protected]
| +--[email protected]
| +--[email protected]
| +--[email protected]
| +--Stringst[email protected]
| +--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
+--[email protected]
| +--[email protected]
| | '---[email protected]
| '---[email protected]
| +--[email protected]
| '---[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
| '---[email protected]
+--[email protected]
'---[email protected]
Includes Express and NPM two modules, and their dependent modules;
7, finally a neat freak. The default path in the user environment variable can be deleted;
The method contained in this article does not need to set the path variable separately;
-end-
Nodejs prefix (global) and cache (cache) settings under Windows