Skip to main content

npm切换源

方案一:使用nrm

安装

npm install -g nrm

列出源的候选项

nrm ls

输出结果:

* npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/

使用淘宝源

nrm use taobao

方案二:改变全局的注册

有很多方法来配置npm的registry地址,下面根据不同情境列出几种比较常用的方法。以淘宝npm镜像举例:

临时使用

npm --registry https://registry.npm.taobao.org install express

持久使用

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

查看结果

npm config get registry

输出结果:

https://registry.npm.taobao.org/