好的,我来给你详细讲解 npm 使用国内淘宝镜像的方法,让你在国内下载 Node.js 包更快、更稳定。
npm 使用官方源:https://registry.npmjs.org/https://registry.npmmirror.com/如果只是临时安装某个包,可以在命令中加 --registry:
npm install express --registry=https://registry.npmmirror.com/npm config set registry https://registry.npmmirror.com/npm config get registry
# 输出:https://registry.npmmirror.com/npm config set registry https://registry.npmjs.org/.npmrc 配置文件在用户目录(Windows:C:\Users\用户名,Linux/Mac:~/.npmrc)中添加:
registry=https://registry.npmmirror.com/.npmrc 覆盖全局配置cnpm 是淘宝 NPM 镜像提供的 命令行工具,用法类似 npm,速度更快:
npm install -g cnpm --registry=https://registry.npmmirror.com/cnpm install expressnpm 使用npm config get registrynpm cache clean --forcenpm install -g npm遇到安装慢的情况,也可以通过淘宝镜像加速:
npm install -g npm --registry=https://registry.npmmirror.com/https://registry.npmmirror.com/--registrynpm config set registry 或 .npmrccnpm,更快捷https://www.52runoob.com/archives/6667