Node与Npm国内最新镜像配置(淘宝镜像/清华大学镜像)
1.淘宝镜像:
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
2.清华大学镜像:
node_mirror: https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/
npm_mirror: https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/npm/
查看电脑当前镜像源:
npm get registry
临时更换镜像:
npm config set registry https://registry.npmmirror.com/
永久更换镜像
npm config set registry https://registry.npmmirror.com/ --global
3.更换 nrm(Node Registry Manager)管理镜像源
nrm 是一个 npm 镜像源管理器,可以让你轻松地在不同的 npm 镜像源之间切换。
安装 nrm
npm install -g nrm
查看可用的镜像源
nrm ls
使用 nrm 切换到某个镜像源
nrm use npmmirror # 使用 npmmirror 镜像源
# 或者使用 nrm use taobao 来使用淘宝的官方镜像源
4.更换 cnpm(一个由淘宝团队开发的 npm 客户端)
cnpm 是淘宝团队为解决国内网络问题而开发的 npm 客户端,它内置了淘宝的 npm 镜像。
安装 cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
使用 cnpm 安装包
cnpm install express
5.使用 yarn 来管理依赖(可选)
Yarn 是另一个流行的 JavaScript 包管理工具,它也可以配置使用国内的镜像源。
安装 yarn
npm install -g yarn
配置 yarn 使用淘宝镜像
yarn config set registry https://registry.npmmirror.com/
注意:
确保在执行任何更改之前,备份当前的配置,以便在需要时可以轻松恢复。可以通过运行 npm config list -l 查看所有配置项及其值。如果要恢复默认设置,可以使用如下命令:
npm config delete registry # 删除 registry 设置,恢复为默认值(通常是官方源)
