[TOC] #### 1. 介绍 ---- nrm 是 npm 的扩展包,可以使用 npm install 进行安装 nrm 是一个 npm 镜像源管理器,可以实现快速地在 npm 源之间进行切换 npm 默认使用的是 npm 官方镜像源,在国内使用官方源下载包会比较慢,一般情况我们都会使用国内镜像加速包的下载 使用下面命令可以查看当前使用的镜像源 ``` npm config ls npm get registry ``` 使用淘宝的镜像源: 这种方式配置镜像源命令有点长,当我们想要切换指定源时,还要百度去查这个源的地址,比较麻烦,此时我们可以使用 nrm 进行快速切换制定的镜像源 ``` npm set registry https://registry.npmmirror.com ``` #### 2. 安装 --- 全局安装 nrm ``` npm install nrm -g ``` 查看 nrm 版本 ``` # 查看 nrm 版本 nrm --version # 查看 nrm 版本简写形式 nrm -V # 查看全局包 nrm npm list nrm -g ``` #### 3. 用法 --- ```bash # 查看可选源 nrm ls # 查看当前源 nrm current # 切换源 nrm use <registry> ``` 添加、删除源 nrm 默认提供一些最常用的镜像源,其实已经足够使用了,但还是想要自定义源,nrm 也提供了相应的命令供开发者操作 ``` # 添加一个新的源 nrm add <registry> <url> # 删除源 nrm del <registry> ``` 测试源的速度: 建议通过测试源的速度,最终选择使用响应较快的镜像源 ``` nrm test <registry> ``` 恢复为默认镜像源 ```bash npm config set registry=https://registry.npmjs.org ```