npm、yarn镜像源管理器nrm、yrm

文章发布于 2023-07-27

nrm和yrm是npm和yarn的镜像源管理器。它们可以对镜像源进行测速、切换、查看镜像源列表等操作。可以更好的管理npm和yarn的镜像源。例如我想使用腾讯的npm镜像源,则只需要使用nrm use tencent一条命令即可。

安装镜像源管理器

记得全局安装

npm i nrm -g
npm i yrm -g

安装完毕之后,查看版本

npm 源管理器nrm

nrm --version
1.2.5

yarn 源管理器yrm

yrm --version
1.0.6

镜像源列表

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.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/

yarn 源列表

yrm ls
* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  yarn --- https://registry.yarnpkg.com

测速

对镜像源进行测试响应时间,查看网络环境。

nrm test npm 
* npm ------ 944ms

nrm test yarn
yarn ----- 954ms

nrm test tencent
tencent -- 178ms

nrm test cnpm 
cnpm ----- 1202ms

nrm test taobao
taobao --- 182ms

nrm test npmMirror
npmMirror - 1779ms

国内tencent和taobao俩大厂比较快。


yrm test npm
* npm ---- 978ms

yrm test cnpm
cnpm --- 1922ms

yrm test taobao
taobao - 296ms

yrm test rednpm
rednpm - 278ms

yrm test npmMirror
npmMirror  2310ms

切换镜像源

npm 镜像源切换

//切换到腾讯npm镜像源
nrm use tencent
Registry has been set to: https://mirrors.cloud.tencent.com/npm/

//查看npm镜像源
npm config get registry
https://mirrors.cloud.tencent.com/npm/

yarn镜像源切换

//切换镜像源
C:\Users\Administrator>yrm use npm
   YARN Registry has been set to: https://registry.npmjs.org/
                         verb config Skipping project config: C:\Users\Administrator/.npmrc. (matches userconfig)
   NPM Registry has been set to: https://registry.npmjs.org/

// 查看yarn镜像源
C:\Users\Administrator>yarn config get registry
https://registry.npmjs.org/