nrm-npm镜像(源)管理工具

之前在npm包的发布的时候简单介绍过nrm.

nrm 是一个对npm的源register进行管理的工具,那么什么是npm的源呢?

什么是镜像(源/register)

我们在进行模块化的开发的时候,package.json文件中往往具有很多的依赖包,而我们进行初始化或者添加依赖的时候,获取依赖包的网址也就是所谓的源了,也即镜像。

默认的镜像(源)的地址是:

https://registry.npmjs.org/

为什么需要使用nrm

由于官网的源的服务器不在内地,因此很多时候我们会觉得下载包的速度非常慢,所以我们会更改使用的镜像,我们最常使用的镜像有淘宝的镜像,阿里的镜像。

我们上传包到私库,服务器地址也会发生变化。

而如果我们每次都过 npm [config] set register [net-url]会非常的麻烦,因此也就有了nrm工具包。

nrm可以管理和快速切换镜像

nrm的安装

因为nrm是一个开发时使用的工具包,因此最好全局安装,方便以后的使用。

nrm -g install nrm

nrm的常用命令

命令说明
nrm ls查看镜像列表
nrm current查看当前使用j镜像
nrm add <名称> <远程地址或私服地址>添加镜像
nrm del <名称>删除镜像
nrm use <名称>切换镜像
nrm test <名称>测试镜像网络传输速度
nrm <–version | -V>查看nrm版本号
nrm <–help | -h>查看nrm的相关信息
nrm home < 名称> [browser]打开镜像的主页
nrm publish [< tarball>|< folder>]上传npm包或命令程序

这里的 < 名称> 可以使用镜像地址,也可以使用 nrm ls 输出的镜像的别名

查看nrm的API

nrm -h

终端输出

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
    set-auth <registry> [value]           Set authorize information for a custom registry with a base64 encoded string or username and pasword
      -a  --always-auth                     Set is always auth
      -u  --username <username>             Your user name for this registry
      -p  --password <password>             Your password for this registry
    set-email <registry> <value>          Set email for a custom registry
    set-hosted-repo <registry> <value>    Set hosted npm repository for a custom registry to publish packages
    del <registry>                        Delete one custom registry
    home <registry> [browser]             Open the homepage of registry with optional browser
    test [registry]                       Show the response time for one or all registries
    publish [<tarball>|<folder>]          Publish package to current registry if current registry is a custom registry.  if you\'re not using custom registry, this command will run npm publish directly
      -t --tag [tag]                        Add tag
      -a --access <public|restricted>       Set access
      -o --otp [otpcode]                    Set otpcode
      -dr --dry-run                         Set is dry run
    help                                  Print this help

  Options:

    -h, --help     output usage information
    -V, --version  output the version number

这个是nrm所有命令,而 nrm [options] [command]说明了命令的组合方式,并列出了所有options的可选项与command的可选项。命令中的 < registry>可以使用镜像地址也可以使用 nrm ls 列出的镜像的别名,例如npm\ yarn\cnpm等

查看镜像列表

带 * 号即为当前使用的配置

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/

查看当前使用镜像

nrm current

终端输出

  npm 

添加镜像

nrm add <名称> <远程地址或私服地址>

例如:nrm add nhost http://xxx.xxx.xxx/nexus/repository/npm-hosted/
终端输出

 add registry nhost success

切换镜像

nrm use <名称>

终端输出

 Registry has been set to:http://xxx.xxx.xxx/nexus/repository/npm-hosted/

删除镜像

nrm del <名称>

测试镜像网络传输速度

nrm test <名称>

终端输出

 nhost -- 65ms

在使用的过程中如果有些命令不记得了可以使用nrm -h查看所有的命令。

<命令名称 -h>这个似乎是个基本规则,基本所有的命令程序都可以通过该方式查看其所有的命令选项。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三知之灵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值