NPM更换国内源
2021-12-15
NPM简介
NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种:
- 允许用户从NPM服务器下载别人编写的第三方包到本地使用。
- 允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用。
- 允许用户将自己编写的包或命令行程序上传到NPM服务器供别人使用。
换源
显示当前的镜像网址:
1
|
npm get registry |
显示:https://registry.npmjs.org/
更换淘宝的镜像网址:
1
|
npm config set registry http: //registry.npm.taobao.org |
再次查看当前镜像:
1
|
npm get registry |
显示:http://registry.npm.taobao.org/
更换成功!
遇到报错
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
*npm ERR! code ENOTFOUND*`` *npm ERR! errno ENOTFOUND* *npm ERR! network request to http: //registry.npm.taobao.org/hexo-helper-live2d failed, reason: getaddrinfo ENOTFOUND registry.npm.taobao.org* *npm ERR! network This is a problem related to network connectivity.* *npm ERR! network In most cases you are behind a proxy or have bad network settings.* *npm ERR! network* *npm ERR! network If you are behind a proxy, please make sure that the* *npm ERR! network 'proxy' config is set properly. See: 'npm help config' * *npm ERR! A complete log of this run can be found in :* *npm ERR! /Users/joseph_wilson/.npm/_logs/2020-03-21T09_51_58_938Z-debug.log* |
使用下面代码解决:
1
|
npm --registry http: //registry.cnpmjs.org info underscore |