如果公司使用代理服務(wù)器蹲蒲,就需要設(shè)置代理埋虹,否則用npm下載什么都不好使
npm config set proxy http://server:port
npm config set https-proxy http://server:port
如果代理需要認(rèn)證的話可以這樣來設(shè)置
npm config set proxy http://username:password@server:port
npm config set https-proxy http://username:pawword@server:port
查看config配置
npm config list
清除npm的代理
npm config delete proxy
npm config delete https-proxy
查看npm內(nèi)部的配置參數(shù),和沒有特別指定的默認(rèn)值。
npm config ls -l
npm獲取配置有6種方式帕识,優(yōu)先級(jí)由高到底泛粹。
命令行參數(shù)。 --proxy http://server:port即將proxy的值設(shè)為http://server:port肮疗。
環(huán)境變量戚扳。 以npm_config_為前綴的環(huán)境變量將會(huì)被認(rèn)為是npm的配置屬性。如設(shè)置proxy可以加入這樣的環(huán)境變量npm_config_proxy=http://server:port族吻。
用戶配置文件≈樵觯可以通過npm config get userconfig查看文件路徑超歌。如果是mac系統(tǒng)的話默認(rèn)路徑就是$HOME/.npmrc。
全局配置文件蒂教∥【伲可以通過npm config get globalconfig查看文件路徑。mac系統(tǒng)的默認(rèn)路徑是/usr/local/etc/npmrc凝垛。
內(nèi)置配置文件懊悯。安裝npm的目錄下的npmrc文件。
默認(rèn)配置(npm config ls -l)梦皮。 npm本身有默認(rèn)配置參數(shù)炭分,如果以上5條都沒設(shè)置,則npm會(huì)使用默認(rèn)配置參數(shù)剑肯。
npm 配置淘寶鏡像
- 臨時(shí)使用
npm --registry https://registry.npm.taobao.org install express
- 持久
npm config set registry https://registry.npm.taobao.org
+++ 配置后可通過下面方式來驗(yàn)證是否成功
npm config get registry
+++ 或
npm info express
- 通過cnpm使用
npm install -g cnpm --registry=https://registry.npm.taobao.org