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
|