NPM Registry Proxy 配置

发布时间: 更新时间: 总字数:231 阅读时间:1m 作者: IP上海 分享 网址
专栏文章
  1. nodejs 版本管理
  2. NPM Registry Proxy 配置(当前)
  3. npm 常用命令
  4. 使用 forever 运行 nodejs 应用

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>"
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数