npm换源方法

共有三种方法。

方法一 命令行修改

1
2
3
4
5
// 查看当前源地址
npm config get registry

// 换源
npm config set registry <要修改的源地址>

例如:

1
2
// 淘宝源
npm config set registry https://registry.npmmirror.com/

方法二 编辑配置文件

以Windows为例,文件路径是:

1
C:\Users\<用户名>\.npmrc

编辑为:

1
registry=https://registry.npmmirror.com/

方法三 用nrm管理npm源(推荐)

1
2
3
npm install -g nrm     // 安装nrm
nrm ls // 查看源列表
nrm use taobao // 换源