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 设置,恢复为默认值(通常是官方源)
相关推荐
遇到困难睡大觉哈哈8 小时前
Harmony os 静态卡片(ArkTS + FormLink)详细介绍
前端·microsoft·harmonyos·鸿蒙
用户47949283569158 小时前
Bun 卖身 Anthropic!尤雨溪神吐槽:OpenAI 你需要工具链吗?
前端·openai·bun
p***43489 小时前
前端在移动端中的网络请求优化
前端
g***B7389 小时前
前端在移动端中的Ionic
前端
拿破轮9 小时前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端
whltaoin9 小时前
【 Web认证 】Cookie、Session 与 JWT Token:Web 认证机制的原理、实现与对比
前端·web·jwt·cookie·session·认证机制
Aerelin10 小时前
爬虫playwright入门讲解
前端·javascript·html·playwright
5***o50010 小时前
前端在移动端中的NativeBase
前端
灵魂学者10 小时前
Vue3.x —— 父子通信
前端·javascript·vue.js·github
1***Q78410 小时前
前端跨域解决方案
前端