查看npm源地址:
npm config get registry
npm官方源地址:
https://registry.npmjs.org
淘宝镜像源地址:
https://registry.npmmirror.com
1.临时使用
npm --registry https://registry.npmmirror.com install express
2.持久使用(推荐)
npm config set registry https://registry.npmmirror.com
配置后可通过下面方式来验证是否成功
npm config get registry 或 npm info express
3.通过cnpm使用(推荐)
npm install -g cnpm --registry=https://registry.npmmirror.com
4、使用cnpm
cnpm install xxx
5、升级cnpm淘宝镜像为最新版本
npm install npm@latest -g cnpm --registry=https://registry.npmmirror.com
6、用npm命令使用淘宝镜像
npm自身就默认代的镜像:http://registry.npmjs.org
npm config set registry https://registry.npmmirror.com
如果用npm命令使用淘宝镜像,再次修改为npm的淘宝链接:
npm config set registry https://registry.npmmirror.com
7、cnpm命令没反应
1、cnpm -v、cnpm install等等cnpm命令执行了都只是跳到下一行就毫无反应。试了npm是没问题的
2、上百度搜了下列三种方式尝试都还是不行
设置环境变量。没用
删除C盘用户目录下的.npmrc文件。也没有用
执行npm config set registry https://registry.npmmirror.com还是没用
3、就试着卸载cnpm重新安装试试,果然可以了
卸载 npm uninstall -g cnpm --registry=https://registry.npmmirror.com
注册 npm set registry https://registry.npmmirror.com
解析 npm set disturl hhttps://registry.npmmirror.com/dist
安装 npm install -g cnpm --registry=https://registry.npmmirror.com