npm设置和取消代理的方法

npm设置和取消代理的方法

手动配置npm代理或者源

设置代理

1
2
npm config set proxy=http://127.0.0.1:8087
npm config set registry=http://registry.npmjs.org

关于https
经过上面设置使用了http开头的源,因此不需要设https_proxy了,否则还要增加一句:

1
npm config set https-proxy http://server:port

代理用户名和密码

1
2
npm config set proxy http://username:password@server:port
npm confit set https-proxy http://username:password@server:port

取消代理

1
2
npm config delete proxy
npm config delete https-proxy

使用nrm快速切换npm源

nrm 是一个 NPM 源管理器,允许你快速地在如下 NPM 源间切换:

  1. taobao

  2. npm

  3. cnpm

  4. strongloop

  5. enropean

  6. australia

  7. nodejitsu

Install

1
sudo npm install -g nrm

如何方法

列出可用的源:

1
2
3
4
5
6
7
8
9
10
nrm ls

npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - http://registry.npm.taobao.org/
eu ----- http://registry.npmjs.eu/
au ----- http://registry.npmjs.org.au/
sl ----- http://npm.strongloop.com/
nj ----- https://registry.nodejitsu.com/
pt ----- http://registry.npmjs.pt/

切换:

1
2
3
nrm use taobao

Registry has been set to: http://registry.npm.taobao.org/

增加源:

1
nrm add <registry> <url> [home]

删除源:

1
nrm del <registry>

测试速度:

1
nrm test