使用nrm工具高效地管理npm源

时间:2023-03-09 23:37:59
使用nrm工具高效地管理npm源

在使用npm时,官方的源下载npm包会比较慢,国内我们基本使用淘宝的源,如果公司内部搭建了一套npm私有仓库,公司内部的源不可能把npm官方的npm包都同步,所以需要切换npm源。如果使用npm/cnpm config set registry xxx来切换源的话,来回切换设置会比较麻烦。使用nrm就可以对源进行高效的管理。使用方法如下:

全局安装nrm:

npm install  nrm -g

常使用的命令包括:ls,use,add,del

1)nrm  ls。列出已经配置好的所有的源地址。

nrm ls
* npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - http://registry.npm.taobao.org/

2)nrm use。切换到指定源上。

nrm add new https://new.com

此时,会提示 :

Registry has been set to: http://r.cnpmjs.org/

再次执行nrm ls,会得到:

 npm ---- https://registry.npmjs.org/
*cnpm --- http://r.cnpmjs.org/
taobao - http://registry.npm.taobao.org/

3)add。添加一个新的源。

nrm add new https://new.com

此时提示:

add registry new success

4)del。删除一个已经存在的源

nrm del new

此时提示:

delete registry new success

其他操作,可以参考

nrm --help
Usage: nrm [options] [command]

  Commands:

    ls                           list all the registries
current show current registry name
use <registry> change registry to registry
add <registry> <url> [home] add one custom registry
del|rm <registry> delete one custom registry
home <registry> [browser] open the homepage of registry with optional browser
test [registry] show response time for specific or all registries
help print this help Options: -h, --help output usage information
-V, --version output the version number

希望大家有更好的工具可以分享。