npm registry

npm registry 是 Node.js 包管理器 npm 使用的公共包存储库,用于存储和分发 Node.js 包。以下是国内外常用的 npm registry 汇总:

国内外 npm registry 对比

Registry 名称 地址 类型 特点 适用场景
npm 官方 registry https://registry.npmjs.org/ 官方 原始数据源,包最全但下载速度较慢(国内) 全球通用,需要最新最全包时使用
yarn 官方 registry https://registry.yarnpkg.com/ 官方 与 npm 官方同步,优化了下载体验 使用 yarn 包管理器时
淘宝 npm 镜像 https://registry.npmmirror.com/ 镜像 国内访问速度快,与官方同步频率高(每10分钟) 国内开发者日常使用
cnpm registry https://r.cnpmjs.org/ 镜像 国内访问速度快,包含一些国内特色包 国内开发者,特别是使用 cnpm 时
华为云 npm 镜像 https://mirrors.huaweicloud.com/repository/npm/ 镜像 稳定可靠,适合企业用户 华为云用户或对稳定性要求高的场景

使用方法

临时使用

bash
npm install --registry=https://registry.npmmirror.com/

永久设置

bash
# 设置淘宝镜像
npm config set registry https://registry.npmmirror.com/

# 查看当前设置
npm config get registry

恢复官方 registry

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

注意事项

  1. 镜像 registry 可能存在一定的同步延迟,如需使用最新发布的包,建议临时切换到官方 registry
  2. 不同镜像 registry 的包完整性可能略有差异,选择时需根据实际需求考虑
  3. 企业内部通常会搭建私有 npm registry,用于管理内部包和提高访问速度
  4. 使用 yarn 时设置 registry 的命令类似:yarn config set registry <registry-url>
最后更新:2026-02-07