Npm代理和镜像源设置

今天又被npm这个东西坑了一次,整理下我找到的一些方法

代理设置

设置代理和https代理

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

认证用户名和密码

1
2
npm config set proxy http://username:[email protected]:port
npm confit set https-proxy http://username:[email protected]:port

删除代理

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

镜像源设置

1
2
npm config set registry http://registry.npmjs.org
npm config set registry https://registry.npm.taobao.org

全局配置文件设置

npm config edit打开.npmrc文件 ,在文件中如下位置添加如下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
;;;;
; npm userconfig file
; this is a simple ini-formatted file
; lines that start with semi-colons are comments.
; read `npm help config` for help on the various options
;;;;

registry=http://registry.npmjs.org/
proxy=http://10.127.0.0.1:1008/

;;;;
; all options with default values
;;;;

使用nrm切换npm源

安装

1
npm install nrm -g

列出可用的源

1
2
3
4
5
6
7
-> nrm ls
npm ---- https://registry.npmjs.org/
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/

切换

1
2
-> npm use taobao
Registry has been set to: http://registry.npm.taobao.org/

增加源

1
nrm add taobao http://registry.npm.taobao.org/

删除源

1
nrm del taobao

测试速度

1
nrm test taobao

npm config相关命令

1
2
3
4
5
6
7
npm config set <key> <value> [-g|--global]
npm config get <key>
npm config delete <key>
npm config list
npm config edit
npm get <key>
npm set <key> <value> [-g|--global]
文章目录
  1. 1. 代理设置
  2. 2. 镜像源设置
  3. 3. 全局配置文件设置
  4. 4. 使用nrm切换npm源
  5. 5. npm config相关命令
|