npm-config

描述

npm從以下來源獲取配置值,按優先級排序:

命令行標記

在命令行上放置--foo bar設置foo配置參數為bar。 一個 -- 參數(argument)告訴cli解析器停止讀取flags.一個 在命令行結尾的--flag參數(parameter)的值將會是true.

環境變量

任何以npm_config_開始的環境變量都會作為配置參數解讀。在環境里設置npm_config_foo=bar將會設置foo配置參數為bar。任何沒有值的環境配置將會默認為true。配置值是不區分大小寫的,所以NPM_CONFIG_FOO=bar的結果一樣。

npmrc Files

相關的四個文件是:

  • 每個項目配置文件(/path/to/my/project/.npmrc)
  • 每個用戶配置文件(~/.npmrc)
  • 全局配置文件($PREFIX/etc/npmrc)
  • npm構建配置文件(/path/to/npm/npmrc)

查看npmrc了解更多細節

默認配置

運行npm config ls -l查看npm內部的配置參數,和沒有特別指定的默認值。

縮寫和其他CLI細節

以下縮寫會在命令行解析:

  • -v : --version
  • -h, -?, --help, -H: --usage
  • -s, --silent: --loglevel silent
  • -q, --quiet: --loglevel warn
  • -d: --loglevel info
  • -dd,--verbose: --loglevel verbose
  • -ddd, --loglevel silly
  • -g: --global
  • -C: --prefix
  • -l: --long
  • -m: --message
  • -p, --porcelain: --parseable
  • -reg: --registry
  • -f : --force
  • -desc: --description
  • -S: -save
  • -D: --save-dev
  • -O: --save-optional
  • -B: --save-bundle
  • -E: --save-exact
  • -y: --yes
  • -n: --yes false
  • ll and la命名:ls --long

如果指定的配置參數解析明確已知的配置參數。比如:

npm ls --par
#same as
npm ls --parseable

如果多個單個字符縮寫串在一起,并且組合沒有去其他配置參數產生歧義,那么就會擴展成多個不同的組成。比如:

npm ls -gpld
# same as
npm ls --global --parseable --long --loglevel info

每個包的配置設置

當運行腳本時(看npm-scripts),如果有一個<name>[<@version>]:<key>的配置參數,package.json “config”keys將在環境變量里被重寫.比如:

{"name":"foo"
,"config":{"port":"8080"}
,"scripts":{"start":"node server.js"}}

并且server.js是這樣的:

http.createServer(...).listen(process.env.npm_package_config_port)

然后用戶可能這樣修改:

npm config set foo:port 80
Config Settings
access
  • Default:restricted
  • Type:Access

當發布scoped packages是,默認的訪問等級是restricted.如果你想要scoped package是公共可見的(和可安裝的)。設置 --access=public. access唯一合法的值是publicrestricted.Unscoped packages的accesslevel總是public.

always-auth
  • Default: false
  • Type:Boolean
    npm在訪問registry的時候強制需要驗證,即使是GET請求
also
  • Default: null
  • Type: String
    當“dev"或者"development"并且本地運行npm shrinkwrap,npm outdated或者npm update,別名是 -dev
bin-links
  • Default: true
  • Type: Boolean
    為可執行包告訴npm創建symlinks(在windows是.cmd)

設置false告訴不要這樣。這是用來解決一些不支持symlink的文件,即使表面是Unix systems.

browser
  • Default: OS X:"open", Windows: "start", Others:"xdg-open"
  • Type: String
    通過npm docs命令調用瀏覽器打開網站
ca
  • Default: The npm CA 認證
  • Type: String, Array或者null
    信任的證書頒發機構簽名證書的SSL連接到注冊表中.在PEM格式的換行應該通過"\n"代替。比如:
ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

設置null讓只有known登記員,或者指定CA認證相信只有特定的登陸認證。
多個CAs可以通過數組形式指定:

ca[]="..."
ca[]="..."

同看strict-ssl配置。

cafile
  • Default: null
  • Type: path
    路徑文件包含一個或多個簽名證書的證書頒發機構。類似于ca設置,但允許多個ca的,以及ca信息存儲在磁盤上的文件中。
cache
  • Default: Windows: %AppData%\npm-cache
    , Posix: ~/.npm
  • Type: path
cache-lock-stale
  • Default:60000(1分鐘)
  • Type:Number

the number of ms before cache folder lockfiles are considered stale.

cache-lock-retries
  • Default:10
  • Type:Number

Number of times to retry to acquire a lock on cache folder lockfiles.

cache-lock-wait
  • Default:10000(10秒)
  • Type: Number

Number of ms to wait for cache lock files to expire.

cache-max
  • Default: Infinity
  • Type: Number

The maximum time (in seconds) to keep items in the registry cache before re-checking against the registry.

Note that no purging is done unless the npm cache clean
command is explicitly used, and that only GET requests use the cache.

cache-min
  • Default: 10
  • Type: Number

The minimum time (in seconds) to keep items in the registry cache before re-checking against the registry.

Note that no purging is done unless the npm cache clean
command is explicitly used, and that only GET requests use the cache.

cert
  • Default: null
  • Type: String

當訪問registry時傳遞的客戶端認證

color
  • Default: true
  • Type: Boolean 或者"always"

如果false,就不會顯示顏色。如果"always",就總是顯示顏色。如果true,只有為ttf file描述才打印顏色代碼

depth
  • Default: Infinity
  • Type: Number

通過npm ls, npm cache lsnpm outdated遞歸目錄時的深度

對于npm outdated,Infinity的設置將會是0,因為給出更多的信息。想要展示所有包和依賴的outdated狀態,使用一個大數字,比如:npm outdated --depth 9999.

description
  • Default: true
  • Type: Boolean
    在npm search里展示描述
dev
  • Default: false
  • Type: Boolean

隨包安裝dev-dependencies

注意如果設置了npatdev-dependencies也會被安裝

dry-run
  • Default:false
  • Type:Boolean

表明你不需要讓npm做出任何更新并且只報告完成了什么。這可以通過修改本地安裝的任何命令,比如:install,update,dedupe,uninstall。這不是當前通過網絡相關命令honored,比如:dist-tags,owner,publish等等。

editor
  • Default: 設置編輯器,或者"vi"在Posix上,或者"notepad"在windows上。
  • Type: 編輯器路徑(path)

命令運行行npm edit或者npm config edit

engine-strict
  • Default: false
  • Type: Boolean

如果設置為true,npm將會直接拒絕安裝(即使考慮安裝)任何與當前Node.js版本不兼容的包

force
  • Default: false
  • Type: Boolean

讓變量命令更強硬

  • 生命周期腳本失敗不阻塞進程
  • 發布時銷毀之前的發布的版本
  • 從registry里請求時跳過緩存
  • 對非npm文件不檢查
fetch-retries
  • Default:2
  • Type: Number

當從registry獲取包時,對retry module使用"retries"配置

fetch-retry-factor
  • Default: 10
  • Type: Number

獲取包時,對retry module使用"factor"配置

fetch-retry-mintimeout
  • Default: 10000(10秒)
  • Type: Number

獲取包時,設置retry module的"minTimeout"

fetch-retry-maxtimeout
  • Default: 10000(10秒)
  • Type: Number

獲取包時,設置retry module的"maxTimeout"

git
  • Default: "git"
  • Type: String

使用git命令。如果電腦上安裝了git,但是不在path里,需要將這個設置為git的全路徑

git-tag-version
  • Default: true
  • Type: Boolean

使用npm version命令時標記提交

global
  • Default: false
  • Type: Boolean

使用全局模式,包會安裝到prefix文件夾而不是當前工作目錄。 查看npm-folders獲取更多的不同行為

  • packages安裝進{prefix}/lib/node_modules}文件夾,而不是當前工作目錄
  • bin files指向{prefix}/bin
  • man pages 指向** {prefix}/share/man**
globalconfig
  • Default: {prefix}/etc/npmrc
  • Type: path

配置全局配置選項的文件

global-style
  • Default: false
  • Type: Boolean

讓npm安裝到本地的node_modules文件夾和全局的node_moudules文件夾是相同的布局。只有直接依賴的會顯示到node_modules并且依賴所依賴的會平級的在他們的node_modules文件夾。這顯然會消除一些重復。如果帶有legacy-bundling,legacy-bundling會更好

group
  • Default: 當前進程的GID
  • Type: String or Number

the group to use when running package scripts in global mode as the root user.

heading
  • Default: "npm"
  • Type: String

所有調試日志輸出開頭的字符

https-proxy
  • Default: null
  • Type: url

用于代理https請求的。

if-present
  • Default: false
  • Type: Boolean

If true, npm will not exit with an error code when run-script
is invoked for a script that isn't defined in the scripts
section of package.json
. This option can be used when it's desirable to optionally run a script when it's present and fail if the script fails. This is useful, for example, when running scripts that may only apply for some builds in an otherwise generic CI setup.

ignore-scripts
  • Default: false
  • Type: Boolean

是true的話,npm不運行在pacakge.json文件里指定的腳本

init-module
  • Default: ~/.npm-init.js
  • Type: path

會被npm init命令加載的模塊。從init-pacakge-json文檔獲取更多信息,或者npm-init

init-author-name
  • Default: ""
  • Type: String
    執行npm init是默認給包設置的作者名
init-author-email
  • Default: ""
  • Type: String
    執行npm init是默認給包設置的作者的郵件
init-author-url
  • Default: ""
  • Type: String
    執行npm init是默認給包設置的作者的主頁
init-license
  • Default: "ISC"
  • Type: String
    執行npm init是默認給包設置的默認證書
init-version
  • Default: ""
  • Type: String
    如果pacakge.json里沒有設置,執行npm init是默認給包設置的版本號
json
  • Default: false
  • Type: Boolean

是否輸出JSON data,而不是普通輸出

這個特性目前只是實驗階段,許多命令的輸出結構還沒有實現JSON,或者可能發生變化。只有npm ls --json命令才是有效的。

key
  • Default: null
  • Type: String
    訪問registry傳輸的客戶端key
legacy-bundling
  • Default: false
  • Type: Boolean

Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping. If used with global-style
this option will be preferred.

link
  • Default: false
  • Type: Boolean

if true, 局部安裝會鏈接到合適的全局安裝了的包。

注意這意味著局部安裝會在同一時間導致things被安裝進全局空間。只有兩種條件之一發生時link才會完成:

  • 包還沒有被安裝到全局環境,或者
  • 全局安裝的版本表明已經被安裝到了局部
local-address
  • Default: undefined
  • Type: IP Address

在連接到npm registry是的本地接口的ip地址。Node小于0.12時必須是IPv4.

loglevel
  • Default: "warn"
  • Type: String
  • Values: "silent", "error", "warn", "http", "info", "verbose", "silly"

日志輸出的等級。失敗的時候,所有的日志會寫到當前工作目錄的npm-debug.log

任何高于設置等級的日志都會被輸出,默認是"warn",就會輸出"warn","error"

logstream
  • Default: process.stderr
  • Type: Stream

在運行時傳給npmlog的stream

如果不能從命令行里設置,但是正以編程方式使用npm,你可能想將日志存在其他地方而不是stderr。

如果設置了color為true,如果stream是TTY,那么會接收到colored輸出。

long
  • Default: false
  • Type: Boolean

npm lsnpm search展示更多的信息

message
  • Default: "%s"
  • Type: String

使用npm version創建版本提交時提交信息。

message里的任何"%s"都會被替換成版本號

node-version
  • Default: process.version
  • Type: semver or false

當檢查package's enginesmap時的node版本號

npat
  • Default: false
  • Type: Boolean

在安裝時運行測試

onload-script
  • Default: false
  • Type: path

在npm加載時,node模塊去require()。在編程時的用法。

only
  • Default: null
  • Type: String

當是dev或者development時,不帶任何參數運行局部npm install,只會有devDependencies(和他們的依賴)會被安裝

當是dev或者development時,運行npm ls, npm outdated或者npm update,是 --dev的別名

當是prod或者production是,無參運行npm install,只有non-devDependencies(和他們的依賴)會被安裝。運行npm ls, npm outdated或者npm update,是 --production的別名

optional
  • Default: true
  • Type: Boolean

試圖安裝在optionalDependencies對象里的包。注意如果包安裝失敗了,整個安裝過程不會終止。

parseable
  • Default: false
  • Type: Boolean

從命令行里的標準輸出解析輸出結構

prefix

安裝全局項的位置,如果在命令行上設置,會強制非全局命令在指定文件夾里運行

production
  • Default: false
  • Type: Boolean

是true就是production模式:

  1. 無參運行npm install時不會將devDependencies安裝在最高的等級
  2. 為生命周期腳本設置NODE_ENV="production"
progress
  • Default: true
  • Type: Boolean

是true時,如果在處理中,npm會顯示一個進度條。stderr是一個TTY。

false就沒有進度條

properietary-attribs
  • Default: true
  • Type: Boolean

在npm創建壓縮包時是否包含私人擴展屬性

Unless you are expecting to unpack package tarballs with something other than npm -- particularly a very outdated tar implementation -- leave this as true.

proxy
  • Default: null
  • Type: url

外部請求的代理。如果設置了HTTP_PROXY或者http_proxy環境變量,proxy設置將會由底層請求庫

rebuild-bundle
  • Default: true
  • Type: Boolean

在安裝后重新構建包依賴

registry

基于npm 包registry的鏈接

rollback
  • Default: true
  • Type: Boolean

刪除失敗的安裝

save
  • Default: false
  • Type: Boolean

安裝包時,作為dependencies保存到package.json

當使用npm rm命令,會從dependencies對象里刪除

只有當已經有package.json文件時才有效。

save-bundle
  • Default: false
  • Type: Boolean

通過使用--save, --save-dev或者--save-optional,包是否會在安裝時保存,然后也放到bundleDependencieslist里。

使用npm rm命令時,會從bundledDependencieslist里移除

save-dev
  • Default: false
  • Type: Boolean

安裝包時,作為devDenpendencies保存到package.json

使用npm rm命令時,會從devDenpendencieslist里移除

僅當存在package.json文件時才有效。

save-exact
  • Default: false
  • Type: Boolean
    使用--save,--save-dev或者-save-optional是保存Dependencies到pacakge.json會配置要求版本而不是npm的默認semver范圍
save-optional
  • Default: false
  • Type: Boolean

保存安裝包到package.json里的optionalDependencies里。

使用npm rm命令時,會從devDependencies對象里移除

僅當存在package.json文件時才有效。

save-prefix
  • Default:'^'
  • Type: String

通過--save或者--save-dev獲取prefixed配置包的什么版本到package.json

比如:如果包有一個版本1.2.3,但是默認設置的版本是可以允許小的升級包的^1.2.3。但是在npm config set save--prefix='~'后,應該設置為~1.2.3

scope
  • Default: ""
  • Type: String

Associate an operation with a scope for a scoped registry. Useful when logging in to a private registry for the first time: npm login --scope=@organization --registry=registry.organization.com, which will cause @organization to be mapped to the registry for future installation of packages specified according to the pattern @organization/package

searchopts
  • Default: ""
  • Type: String
    搜索時空格分隔的選項
searchexclude
  • Default:""
  • Type: String
    空格分隔的選項限制搜索的結果。
searchsort
  • Defautl: "name"
  • Type: String
  • Values:"name","-name","date","-date","description","-description","keywords","-keywords"

顯示的字段排序搜索結果。前綴-表明逆向排序。

shell
  • Default: SHEELL環境變量,Posix上是base,windows上是cmd
  • Type: path

運行npm explore命令的shell

shrinkwrap
  • Default: true
  • Type: Boolean

如果是false,安裝時會忽略掉npm-shrinkwrap.json

sign-git-tag
  • Default: false
  • Type: Boolean

為true時,npm version命令會使用-s標記版本添加到signature.

注意git需要你設置GPG keys,在git配置這個工作屬性

strict-ssl
  • Default: true
  • Type: Boolean

通過https請求registry是否進行SSL可以驗證,同ca配置

tag
  • Default:latest
  • Type: String

如果在安裝包時不告訴指定的版本,就會安裝指定的tag

同樣tag會添加到pacakge@version,通過npm tag命令指定,如果沒有顯示的tag給

tag-version-prefix
  • Default: "v"
  • Type: String

If set, alters the prefix used when tagging a new version when performing a version increment using npm-version. To remove the prefix altogether, set it to the empty string: "".
Because other tools may rely on the convention that npm version tags look likev1.0.0
, only use this property if it is absolutely necessary. In particular, use care when overriding this setting for public packages.

tmp
  • Default: TMPDIR environment variable, or "/tmp"
  • Type: path

Where to store temporary files and folders. All temp files are deleted on success, but left behind on failure for forensic purposes.

unicode
  • Default: false on windows, true on mac/unix systems with a unicode locale
  • Type: Boolean

When set to true, npm uses unicode characters in the tree output. When false, it uses ascii characters to draw trees.

unsafe-perm
  • Default: false if running as root, true otherwise
  • Type: Boolean

Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.

usage
  • Default: false
  • Type: Boolean

Set to show short usage output (like the -H output) instead of complete help when doing npm-help

user
  • Default: "nobody"
  • Type: String or Number

The UID to set to when running package scripts as root.

userconfig
  • Default: ~/.npmrc
  • Type: path

The location of user-level configuration settings.

umask
  • Default: 022
  • Type: Octal numeric string in range 0000..0777 (0..511)

The "umask" value to use when setting the file creation mode on files and folders.

Folders and executables are given a mode which is 0777 masked against this value. Other files are given a mode which is 0666 masked against this value. Thus, the defaults are 0755 and 0644 respectively.

user-agent
  • Default: node/{process.version} {process.platform} {process.arch}
  • Type: String

Sets a User-Agent to the request header

version
  • Default: false
  • Type: boolean

If true, output the npm version and exit successfully.

Only relevant when specified explicitly on the command line.

versions
  • Default: false
  • Type: boolean

If true, output the npm version as well as node's process.versions map, and exit successfully.

Only relevant when specified explicitly on the command line.

viewer
  • Default: "man" on Posix, "browser" on Windows
  • Type: path

The program to use to view help content.

Set to "browser" to view html help content in the default web browser.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,572評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,071評論 3 414
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,409評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,569評論 1 307
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,360評論 6 404
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,895評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 42,979評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,123評論 0 286
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,643評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,559評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,742評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,250評論 5 356
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 43,981評論 3 346
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,363評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,622評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,354評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,707評論 2 370

推薦閱讀更多精彩內容