一、默认情况下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.

本文介绍了如何查看和设置Node.js的npm全局模块和缓存目录。通过`npm config ls`命令查看默认配置,然后使用`npm config set`命令分别设置prefix为自定义的全局模块路径和cache为自定义的缓存路径。设置后,通过再次运行`npm config ls`确认配置已生效。

1390

被折叠的 条评论
为什么被折叠?



