安装NodeJS之后使用npm来安装包使用的是国外的地址,经常会出现超时错误,可以通过修改为国内的淘宝源来加速安装。
一、临时配置
npm --registry https://registry.npm.taobao.org install express
二、永久配置
npm config set registry https://registry.npm.taobao.org
图1:设置镜像为淘宝镜像
验证:
图2:验证配置结果
三、如果想恢复原来仓库镜像
npm config set registry https://registry.npmjs.org
四、使用cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
图3:安装cnpm
配置cnpm环境变量
图4:cnpm的路径
图5:设置环境变量——系统变量
使用cnpm安装模块:
图6:使用cnpm安装webpack模块