npm config

查看和修改 npm 配置,包括 registry、proxy 等

语法

npm config <set|get|list|delete> [key] [value]

参数

参数说明示例级别
set <key> <value> 设置配置项 npm config set registry https://registry.npmmirror.com 常用
get <key> 获取配置项 npm config get registry 常用
list 列出所有配置 npm config list 常用
delete <key> 删除配置项 npm config delete proxy 常用

示例

切换到国内镜像

npm config set registry https://registry.npmmirror.com
加速国内下载

恢复官方源

npm config set registry https://registry.npmjs.org

查看当前 registry

npm config get registry

设置代理

npm config set proxy http://127.0.0.1:7890
通过代理下载

常见错误

npm ERR! network request failed 网络问题,尝试切换 registry 或设置代理

技巧

相关命令