Npm 源管理 nrm
# Npm 源管理 nrm
# 📖. 前言
npm 包有很多的镜像源,有的源有的时候访问失败,有的源可能没有最新的包等等,所以有时候需要切换 npm 的源,nrm 包就是解决快速切换问题的。
nrm 可以帮助您在不同的 npm 源地址之间轻松快速的切换。
nrm 内置了如下源:
经过本人实测,nj、rednpm、edunpm 源访问失败(2022-04-22)。
# 一. 安装
打开终端,输入命令:
$ npm install -g nrm
1
查看是否安装成功
$ nrm --version
1
# 二. 使用
# 1. 列出可使用源
$ nrm 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/
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
注: 前面带 * 号的表示正在使用的源
# 2. 切换源
$ nrm use npm
Registry has been set to: https://registry.npmjs.org/
1
2
3
2
3
# 3. 添加源
$ nrm add company http://npm.company.com/
add registry company success
1
2
3
2
3
注:
- URL 最后的 / 也可以不带,下面两个URL都是可以的:
http://npm.company.com/
http://npm.company.com
- [home] 参数用于 nrm home 命令,用来查看源的主页。
# 4. 删除源
$ nrm del company
delete registry company success
1
2
3
2
3
注:nrm del 命令不能删除 nrm 自己内置的源。
# 5. 测试源速度
测试一个源的响应时间:
$ nrm test npm
* npm ---- 833ms
1
2
3
2
3
测试所有源的速度:
$ ~ nrm test
* npm ---- 807ms
cnpm --- 374ms
taobao - 209ms
nj ----- Fetch Error
rednpm - Fetch Error
npmMirror 1056ms
edunpm - Fetch Error
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 6. 访问源主页
如果你想访问源的主页,可以在终端输入下面命令:
$ nrm home taobao
1
此命令会在浏览器中打开淘宝源的主页:https://npm.taobao.org/ (opens new window)
注: 如果要查看自己的添加的源的主页,那么在添加源的时候就要把主页戴上:
$ nrm add company http://npm.company.com/ http://npm.company.com/
1
如果添加源的时候没有写 home 信息,那么 nrm home
命令不会有效果。
# 三. 不使用nrm切换源
如果不是 nrm 也能切换源,只不过比较麻烦。
- 查看当前使用的源
$ npm config get registry
1
- 设置一个源
$ npm config set registry https://registry.npm.taobao.org/
1
设置成功后终端不会有任何输出。
- 安装包使用特定源
- 全部使用特定源安装:
npm install --registry=https://registry.npm.taobao.org
- 安装一个包使用特定源:
npm i logo --registry=https://registry.npm.taobao.org
- 全部使用特定源安装:
上次更新: 2022/07/08, 18:18:02