NRM —— 简单好用的镜像源管理工具

2,683 阅读1分钟

什么 NRM

NRM 的全称是 npm registry manager ,是一个 npm 的镜像源管理工具

为什么要用 NRM

在之前的一篇文章中(https://juejin.cn/post/6844904102967656456)讲到了如何发布 npm 包到npm服务器,一般公司都有自己的私服,这样就需将镜像源通过如下的方式进行来回的切换,操作繁琐易出错。

npm config set registry https://registry.npmjs.org/

如何安装 NRM

npm install -g nrm

利用 NRM 查看当前所有镜像源

nrm ls

结果如下:

  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  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/
* qunhe ------ http://npm-registry.qunhequnhe.com/

注:其中带 * 号的是当前使用的源

切换镜像源

// 切换至 taobao 的镜像源
nrm use taobao
// 切换至 cnpm 的镜像源
nrm use cnpm

添加镜像源

你可以增加定制的镜像源,特别适用于添加企业内部的私有源,执行命令 nrm add <registry> <url>,其中 reigstry 为源名,url 为源的路径。

nrm add registry http://npm-registry.qunhequnhe.com/

删除镜像源

// 其中 reigstry 为源名
nrm del <registry>

测试镜像源的响应时间

nrm test npm