node设置镜像源详细教程

在Node.js环境中,你可以通过设置npm或yarn的镜像源来加速依赖包的下载。以下是如何设置npm和yarn的镜像源的详细步骤:

使用npm设置镜像源

  1. 临时设置镜像源

    你可以在安装包时临时指定镜像源,例如:

    sh 复制代码
    npm install package-name --registry=https://registry.npmmirror.com
  2. 永久设置镜像源

    你可以通过配置npm的全局配置文件来永久设置镜像源:

    sh 复制代码
    npm config set registry https://registry.npmmirror.com

    你可以通过以下命令验证镜像源是否设置成功:

    sh 复制代码
    npm config get registry

使用yarn设置镜像源

  1. 临时设置镜像源

    你可以在安装包时临时指定镜像源,例如:

    sh 复制代码
    yarn add package-name --registry https://registry.npmmirror.com
  2. 永久设置镜像源

    你可以通过配置yarn的全局配置文件来永久设置镜像源:

    sh 复制代码
    yarn config set registry https://registry.npmmirror.com

    你可以通过以下命令验证镜像源是否设置成功:

    sh 复制代码
    yarn config get registry

常用的npm镜像源

以下是一些常用的npm镜像源地址:

  • npm官方镜像

    sh 复制代码
    https://registry.npmjs.org/
  • 淘宝镜像

    sh 复制代码
    https://registry.npm.taobao.org/
  • 中国科学技术大学镜像

    sh 复制代码
    https://mirrors.ustc.edu.cn/npm/

示例

假设你想将npm和yarn的镜像源都设置为淘宝镜像,具体操作如下:

sh 复制代码
# 设置npm镜像源
npm config set registry https://registry.npmmirror.com

# 验证npm镜像源
npm config get registry

# 设置yarn镜像源
yarn config set registry https://registry.npmmirror.com

# 验证yarn镜像源
yarn config get registry

这样配置,你的npm和yarn都会使用淘宝镜像源进行包的下载会加速在国内的下载速度。

相关推荐
越努力越幸运5083 小时前
node.js学习三:Session,jwt,cors,mysql,api的学习
node.js
超哥的一天3 小时前
【前端】每天一个知识点-NPM
前端·node.js
r***18643 小时前
最新最详细的配置Node.js环境教程
node.js
8***J1824 小时前
Node.js(v16.13.2版本)安装及环境配置教程
node.js
一字白首4 小时前
Node.js 入门,进阶核心:CommonJS+ES6 模块化、包、Express 与跨域
node.js·es6·express
李少兄4 小时前
解决 `npm install` 卡在 `idealTree: sill idealTree buildDeps` 的排查与修复
前端·npm·node.js
程序员爱钓鱼4 小时前
Node.js 架构与事件循环(Event Loop)深度解析
后端·node.js·trae
程序员爱钓鱼4 小时前
Node.js 起源与发展:改变后端世界的一次“意外革命”
后端·node.js·trae
f***14775 小时前
Node.js npm 安装过程中 EBUSY 错误的分析与解决方案
前端·npm·node.js