Skip to content

cnpm

cnpm 介绍

cnpm介绍

cnpm 是一个 npm 的替代工具,cnpm 服务器部署在国内,主要用于在国内优化 npm 包的下载速度,cnpm 由淘宝团队创建和维护,又称:

npm 原始服务器地址:https://registry.npmjs.org/

cnpm 服务器地址为:https://registry.npmmirror.com/

安装

对于 cnpm 的使用有两种方式:

  • 第一种方式:安装 cnpm 包管理器
shell
npm install cnpm -g --registry=https://registry.npmmirror.com

该种方式是全局安装了 cnpm 包,以后全局用 cnpm 命令即可,

  • 第二种方式:仅修改 npm 服务器地址
shell
npm config set registry https://registry.npmmirror.com

该种方式只是修改了 npm 服务器地址,以后还是用 npm 命令。
备注 1:使用 npm config get registry 或 cnpm config get registry 可以查看服务器地址。
备注 2:npm 原始远程服务器地址为https://registry.npmjs.org/

nrm(推荐使用)

nrm(NPM Registry Manager)是一个用于管理 npm 注册表的工具,方便用户在多个 npm 注册表之间切换。它适用于在不同的 npm 源之间快速切换。

  • 安装 nrm
shell
npm install -g nrm

pnpm add -g nrm
  • 列出可用地址
shell
nrm ls

列出可用地址

  • 测试各地址速度
shell
nrm test
  • 切换到指定地址
shell
nrm use 别名
例如:nrm use taobao
  • 添加新地址
shell
nrm add 别名 URL
  • 删除地址
shell
nrm del 别名