NPM Registry Proxy 配置,解决访问国外 NPM 源超时、中断等问题。
Porxy
$ npm config set proxy http://server:port
$ npm config set https-proxy http://server:port
$ cat ~/.npmrc
registry=https://mirrors.cloud.tencent.com/npm/
home=https://mirrors.cloud.tencent.com/npm/
nrm
快速切换npm源,安装
sudo npm install -g nrm
查看源:
$ nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.nlark.com/
npmMirror ---- https://skimdb.npmjs.com/registry/
测速:
nrm test
切换:
nrm use tencent
其他:
nrm add <registry> <url> [home]
nrm del <registry>
私有 Registry
可以使用 https://github.com/verdaccio 搭建,示例如下:
# npm 安装
npm install --location=global verdaccio@6-next
# yarn 安装
yarn global add verdaccio@6-next
# Docker 安装
docker pull verdaccio/verdaccio:nightly-master
verdaccio
npm set registry http://localhost:4873/
- UI http://localhost:4873/
debug 日志
npm install --timing --loglevel verbose
F&Q
self signed bug
request to https://registry.npmjs.org/yarn failed, reason: self signed certificate in certificate chain
# npm
npm config set strict-ssl false -g
# npm set strict-ssl false
# yarn
yarn config set "strict-ssl" false
# env
set NODE_TLS_REJECT_UNAUTHORIZED=0
# 设置 ca
npm config set cafile "<path to your certificate file>"