Nodejs修改全局仓库设置方案

一、默认情况下nodejs内置的npm会把模块缓存在:“C:\Users\用户\AppData\Roaming\npm”
打开cmd -> 输入命令 npm config ls ,查看系统默认的npm仓库目录。

C:\Users\Daniel>npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.10 node/v14.15.4 win32 x64"

; builtin config undefined
prefix = "C:\\Users\\Daniel\\AppData\\Roaming\\npm"

; node bin location = D:\JavaFile\Nodejs\node.exe
; cwd = C:\Users\Daniel
; HOME = C:\Users\Daniel
; "npm config ls -l" to show all defaults.

二、设置自定义全局仓库,新建model和cache。其中module对应prefix,cache对应cache。

npm config set prefix "D:\JavaFile\Nodejs\model"
npm config set cache "D:\JavaFile\Nodejs\cache" 

三、查看配置是否生效

C:\Users\Daniel>npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.10 node/v14.15.4 win32 x64"

; userconfig C:\Users\Daniel\.npmrc
cache = "D:\\JavaFile\\Nodejs\\cache"
prefix = "D:\\JavaFile\\Nodejs\\model"

; builtin config undefined

; node bin location = D:\JavaFile\Nodejs\node.exe
; cwd = C:\Users\Daniel
; HOME = C:\Users\Daniel
; "npm config ls -l" to show all defaults.
原文地址:https://www.cnblogs.com/InternetJava/p/15731273.html