wangshuo'blog

wangshuo'blog

npm | npm install 配置代理

npm | npm install 配置代理


命令如下

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

举例

1
2
npm config set proxy http://127.0.0.1:8889
npm config set https-proxy http://127.0.0.1:8889

或者直接编辑 ~/.npmrc 文件

1
2
3
proxy=http://username:password@host:port
https-proxy=http://username:password@host:port
https_proxy=http://username:password@host:port

查看 npm 配置信息

1
npm config list

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
PS D:\> npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.16 node/v14.19.0 win32 x64"

; userconfig C:\Users\makhel\.npmrc
proxy = "http://127.0.0.1:8889/"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = D:\testRepo\.git
; HOME = C:\Users\makhel
; "npm config ls -l" to show all defaults.

扩展

yarn 配置代理

1
2
yarn config set proxy http://username:password@host:port
yarn config set https-proxy http://username:password@host:port