描述
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
唯一合法的值是public
和restricted
.Unscoped packages的access
level總是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 ls
和npm outdated
遞歸目錄時的深度
對于npm outdated
,Infinity
的設置將會是0,因為給出更多的信息。想要展示所有包和依賴的outdated狀態,使用一個大數字,比如:npm outdated --depth 9999
.
description
- Default: true
- Type: Boolean
在npm search里展示描述
dev
- Default: false
- Type: Boolean
隨包安裝dev-dependencies
注意如果設置了npat
,dev-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 ls
和npm search
展示更多的信息
message
- Default: "%s"
- Type: String
使用npm version
創建版本提交時提交信息。
message里的任何"%s"都會被替換成版本號
node-version
- Default: process.version
- Type: semver or false
當檢查package's engines
map時的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
- Default : 查看npm-folders
- Type: path
安裝全局項的位置,如果在命令行上設置,會強制非全局命令在指定文件夾里運行
production
- Default: false
- Type: Boolean
是true就是production
模式:
- 無參運行
npm install
時不會將devDependencies安裝在最高的等級 - 為生命周期腳本設置
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
- Default: https://registry.npmjs.org/
- Type: url
基于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
,包是否會在安裝時保存,然后也放到bundleDependencies
list里。
使用npm rm
命令時,會從bundledDependencies
list里移除
save-dev
- Default: false
- Type: Boolean
安裝包時,作為devDenpendencies
保存到package.json
里
使用npm rm
命令時,會從devDenpendencies
list里移除
僅當存在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.