npm 安装源

我们在使用官方提供的npm源安装各种依赖包的时候,下载速度会很慢,通常需要更换npm源。
我们可以在终端中输入命令 npm config list 来查看 npm 源地址,默认地址为

metrics-registry = "https://registry.npmjs.org/"

国内常用的npm源地址为淘宝镜像:https://registry.npm.taobao.org/

方式一:使用命令直接更换

在终端输入以下命令,即可设置npm源地址为淘宝镜像。

npm set registry https://registry.npm.taobao.org/

这时使用 npm config list 查看 npm 源地址就变为

更改后的npm源

删除方式为:npm config rm registry

方式二:使用nrm管理npm源

nrm是用来专门管理npm源地址的工具,我们使用nrm可以很方便的切换npm源地址。

  1. 全局安装nrm
 npm install nrm -g --save 
  1. nrm有默认配置,使用 nrm ls 查看,带 * 即为当前源地址
    nrm查看配置项

  2. nrm切换淘宝镜像

nrm use taobao
  1. 使用nrm添加镜像地址
nrm add r_name r_url # r_name 为镜像名字,r_url 为镜像地址
  1. 删除nrm镜像
nrm del r_name
  1. 测试镜像速度
nrm test r_name

参考文章:
https://www.cnblogs.com/Sky-Raining/p/10313600.html
https://www.cnblogs.com/wangmeijian/p/7072053.html

原文地址:https://www.cnblogs.com/zhizou/p/15082950.html