国内 npm 镜像源推荐

国内 npm 镜像源推荐

除了常用的淘宝镜像(https://registry.npmmirror.com),还有以下国内 npm 镜像源可供选择:


1. CNPM(阿里云)
  • 地址:https://r.cnpmjs.org/
  • 特点:
    • 由 cnpm 提供,支持同步 npm 官方仓库。
    • 提供更快的下载速度和稳定性。

使用方法:

bash 复制代码
npm config set registry https://r.cnpmjs.org/

2. 京东镜像(JFrog Artifactory)
  • 地址:https://registry.jfrog.org/npm/registry
  • 特点:
    • 由京东提供,基于 JFrog Artifactory。
    • 支持高并发访问,适合企业级用户。

使用方法:

bash 复制代码
npm config set registry https://registry.jfrog.org/npm/registry

3. 腾讯云镜像
  • 地址:https://mirrors.cloud.tencent.com/npm/
  • 特点:
    • 由腾讯云提供,适用于使用腾讯云服务的开发者。
    • 提供稳定的下载速度。

使用方法:

bash 复制代码
npm config set registry https://mirrors.cloud.tencent.com/npm/

4. 华为云镜像
  • 地址:https://repo.huaweicloud.com/repository/npm/
  • 特点:
    • 由华为云提供,适用于使用华为云服务的开发者。
    • 提供快速的国内访问速度。

使用方法:

bash 复制代码
npm config set registry https://repo.huaweicloud.com/repository/npm/

5. 网易镜像
  • 地址:http://mirrors.163.com/npm/
  • 特点:
    • 由网易提供,适用于国内用户。
    • 提供稳定的下载速度。

使用方法:

bash 复制代码
npm config set registry http://mirrors.163.com/npm/

切换镜像源后验证

切换镜像源后,可以通过以下命令验证是否成功:

bash 复制代码
npm config get registry

如果输出为你设置的镜像源地址,则说明切换成功。


注意事项

  1. 临时使用镜像源

    如果只想在当前会话中使用某个镜像源,可以添加 --registry 参数。例如:

    bash 复制代码
    npm install electron --save-dev --registry=https://registry.npmmirror.com
  2. 恢复默认源

    如果需要恢复为官方 npm 源,可以运行以下命令:

    bash 复制代码
    npm config set registry https://registry.npmjs.org/
  3. 选择合适的镜像源

    根据你的网络环境和地理位置选择最合适的镜像源。通常情况下,淘宝镜像(https://registry.npmmirror.com)是大多数开发者的首选。

希望这些信息对你有所帮助!

相关推荐
csgo打的菜又爱玩27 分钟前
Vue 基础(实战模板与命名指南)
前端·javascript·vue.js
ding_zhikai1 小时前
SD:在一个 Ubuntu 系统安装 stable diffusion Web UI
前端·ubuntu·stable diffusion
gerrgwg3 小时前
Vue-library-start,一个基于Vite的vue组件库开发模板
前端·javascript·vue.js
你的人类朋友4 小时前
【Node】单线程的Node.js为什么可以实现多线程?
前端·后端·node.js
iナナ5 小时前
Spring Web MVC入门
java·前端·网络·后端·spring·mvc
驱动探索者5 小时前
find 命令使用介绍
java·linux·运维·服务器·前端·学习·microsoft
开心不就得了5 小时前
自定义脚手架
前端·javascript
星晨雪海6 小时前
怎么格式化idea中的vue文件
前端·vue.js·intellij-idea
没事多睡觉6666 小时前
Vue 虚拟列表实现方案详解:三种方法的完整对比与实践
前端·javascript·vue.js
white-persist7 小时前
Burp Suite模拟器抓包全攻略
前端·网络·安全·web安全·notepad++·原型模式