npm切换下载源为国内的镜像源

npm在国内存在下载速度比较慢的问题。为解决这个问题,需要切换npm下载源为国内的镜像源

 

npm国内下载镜像汇总:

npm官方原始镜像: https://registry.npmjs.org/

淘宝npm镜像:http://registry.npmmirror.com

阿里云npm镜像: https://npm.aliyun.com

腾讯云npm镜像: https://mirrors.cloud.tencent.com/npm/

华为云npm镜像: https://mirrors.huaweicloud.com/repository/npm/

网易npm镜像: https://mirrors.163.com/npm/

中科大开源镜像站: http://mirrors.ustc.edu.cn/

清华大学开源镜像站: https://mirrors.tuna.tsinghua.edu.cn/

 

查看当前使用的npm镜像源,使用命令:

npm config get registry

 

切换npm镜像源,使用命令:

npm config set registry http://mirrors.cloud.tencent.com/npm/

切换为国内的镜像源之后,确认是否切换成功,查看当前使用的npm镜像,命令

npm config get registry 

 

使用nrm管理镜像源

nrm是一个npm源管理工具,可以使用nrm切换不同的镜像源

先恢复官方的镜像源,使用命令

npm config set registry https://registry.npmjs.org/

安装nrm,命令:

npm install -g nrm

使用nrm查看有哪些npm镜像源, 命令:

nrm ls

运行命令,会得到类似以下结果的输出

npm ---- https://registry.npmjs.org/

yarn ---- https://registry.yarnpkg.com/

tencent - https://mirrors.cloud.tencent.com/npm/

taobao-- https://registry.npmmirror.com/

huawei -- https://repo.huaweicloud.com/repository/npm/

5b70b661114c6f65cfe8526a5b8545ae

使用nrm切换npm镜像源,需要用到nrm ls命令中得到的结果,命令如下:

nrm taobao

 

恢复官方源,运行命令:

npm config set registry https://registry.npmjs.org/