npm-config
npm 設定について、仔細に記述します。
説明
npm は設定を6ソースから以下の優先順位に従って読み込みます:
コマンドラインのフラグ
--foo bar
とコマンドラインから入力した時、
foo
に値
"bar"
が設定されます。
--
の引数は cli parser(訳注※コマンドライン解釈プログラム) にフラグの読み込み中止を宣言します。
--flag
パラメータをコマンドの end 最後に宣言した場合、 これは値
true
を設定します。
環境変数
npm_config_
から始まる全ての環境変数は設定パラメータとして解釈されます。
例えば
npm_config_foo=bar
と環境変数を設定しておけば、
foo
パラメータに
bar
がセットされます。
値が設定されなかった全ての環境変数による設定は値が
true
となります。大文字と小文字の区別はないので、
NPM_CONFIG_FOO=bar
は同じ設定がされます。
npmrc ファイル
記述場所として適切なファイルは3つです:
- ユーザー毎の設定ファイル (~/.npmrc)
- システム設定ファイル ($PREFIX/npmrc)
- npm のビルトイン設定ファイル (/path/to/npm/npmrc)
詳細は npmrc(5) を参照下さい。
規定値
設定パラメータは npm の内部パラメータであり、規定値を持っています。
省略形と正式コマンド
以下は解釈される省略形式です:
-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
-l
:--long
-m
:--message
-p
,--porcelain
:--parseable
-reg
:--registry
-v
:--version
-f
:--force
-desc
:--description
-S
:--save
-D
:--save-dev
-O
:--save-optional
-B
:--save-bundle
-y
:--yes
-n
:--yes false
ll
andla
commands:ls --long
特定のパラメータが明確に認識された場合、認識されたパラメータとして 展開されます。例えば:
npm ls --par
# は以下と同じです:
npm ls --parseable
1文字の省略形コマンドが連なり、且つ、それが明確に他の設定と異なる と認識された場合、多コマンド群として展開されます。例えば:
npm ls -gpld
# は以下と同じです:
npm ls --global --parseable --long --loglevel info
パッケージ毎の設定
スクリプト (参考:
npm-scripts(7)
) を実行する時、package.json "config" キーは
以下の表記で指定されたコンフィグパラメータで上書きされます。
<name>[@<version>]:<key>
例えば、もし package.json に以下のような記述があった場合:
{ "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
詳細は package.json(5) を参考下さい。
設定項目
always-auth
- Default: false
- Type: Boolean
npm レジストリへのアクセスに、GET
リクエストも含め
常に認証を要求します。
bin-links
- Default:
true
- Type: Boolean
事項可能な package に対して npm にシンボリックリンク (もしくは Windows 上の
.cmd
) の作成を要求します。
実行しないようにするには、falseを設定します。これは Unix システムの ようでシンボリックリンクをサポートしていない場合の凌ぎで使うことが できます。
browser
- Default: OS X:
"open"
, Windows:"start"
, Others:"xdg-open"
- Type: String
npm docs
で開くブラウザです。
ca
- Default: The npm CA certificate
- Type: String or null
レジストリにアクセスする際の SSL の CA です。
"認知された " 認証者であったり、特別に信頼性のある特定の CA に対してのみ
null
を設定することができます。
strict-ssl
設定も併せて参照下さい。
cache
- Default: Windows:
%AppData%\npm-cache
, Posix:~/.npm
- Type: path
npm のキャッシュファイルの場所です。
npm-cache(1)
も参照ください。
cache-lock-stale
- Default: 60000 (1 minute)
- Type: Number
キャッシュフォルダのロックされたファイルが最新でないとして扱われる までの期間(ミリ秒)です。
cache-lock-retries
- Default: 10
- Type: Number
ロック中のファイルに対して、ロック取得を再試行する回数です。
cache-lock-wait
- Default: 10000 (10 seconds)
- Type: Number
ロック期限切れを待つためのミリ秒です。
cache-max
- Default: Infinity
- Type: Number
レジストリにキャッシュの再チェックを書ける前に キャッシュに保持しておく最大秒数です。
キャッシュは
npm cache clean
コマンドを直接実行しないと、完全にクリアされず、GETリクエストは
キャッシュを利用する点に注意して下さい。
cache-min
- Default: 10
- Type: Number
レジストリにキャッシュの再チェックを書ける前に キャッシュに保持しておく最小秒数です。
キャッシュは
npm cache clean
コマンドを直接実行しないと、完全にクリアされず、GETリクエストは
キャッシュを利用する点に注意して下さい。
color
- Default: true on Posix, false on Windows
- Type: Boolean or
"always"
false の場合、色づけしません。
"always"
の場合、常に色づけします。true の時は tty ファイルの記述に対して
のみ色づけします。
coverage
- Default: false
- Type: Boolean
// check
テストハーネスが
npm_config_coverage
環境変数を返す時、カバレッジオプションを付加するための
フラグです。
depth
- Default: Infinity
- Type: Number
npm ls
と
npm cache ls
についての再帰的なディレクトリの
深さです。
description
- Default: true
- Type: Boolean
npm search
の説明を見て下さい。
dev
- Default: false
- Type: Boolean
dev-dependencies
に従ってパッケージのインストールを
行います。
dev-dependencies
は
npat
フラグがセットされたときもインストールされます。
editor
- Default:
EDITOR
environment variable if set, or"vi"
on Posix, or"notepad"
on Windows. - Type: path
npm edit
もしくは
npm config edit
を実行するためのものです。
engine-strict
- Default: false
- Type: Boolean
true をセットしていると、現在の Node.js のバージョンと 整合性が無いパッケージのインストールをかたくなに拒絶 (もしくはインストールの是非を問う)します。
force
- Default: false
- Type: Boolean
様々なコマンドを強制的なものにします。
- ライフサイクルScriptの失敗はプロセスを止めません。
- 配布済み(訳注※ npm publish による)のバージョンを 強制的に上書きます。
- レジストリからのアクセスに対してキャッシュを無視します。
- npm と適合しないファイルに対するチェックをしません。
fetch-retries
- Default: 2
- Type: Number
レジストリからのパッケージの走査における
retry
モジュールのための
"retries" の設定です。
fetch-retry-factor
- Default: 10
- Type: Number
パッケージの走査における
retry
モジュールのための
"factor" の設定です。
fetch-retry-mintimeout
- Default: 10000 (10 seconds)
- Type: Number
パッケージの走査における
retry
モジュールのための
"minTimeout" の設定です。
fetch-retry-maxtimeout
- Default: 60000 (1 minute)
- Type: Number
パッケージの走査における
retry
モジュールのための
"maxTimeout" の設定です。
git
- Default:
"git"
- Type: String
git コマンドを使う為のコマンドです。もし git がコンピュータに
インストールされていて、しかしながら
PATH
(訳注※環境変数) に設定されていなければ、
ここに git バイナリへのフルパスを指定します。
global
- Default: false
- Type: Boolean
"e;global"e;モードで実行します。この場合、
パッケージは実行ディレクトリではなく
prefix
フォルダにインストールされます。
挙動の詳細な違いは
npm-folders(5)
を見て下さい。
- パッケージは実行ディレクトリではなく、
{prefix}/lib/node_modules
に にインストールされます。 - bin ファイルは
{prefix}/bin
にリンクされます。 - man ページは
{prefix}/share/man
にリンクされます。
globalconfig
- Default: {prefix}/etc/npmrc
- Type: path
全体に適用する設定オプション用設定ファイルです。The config file to read for global config options.
globalignorefile
- Default: {prefix}/etc/npmignore
- Type: path
全てのユーザー、全てのプロジェクトに適用する、 対象外ファイルパターンの指定ファイルです。
もしファイルはないが、 "gitignore" ファイルが同ディレクトリに ある場合、これを代わりに用います。
group
- Default: GID of the current process
- Type: String or Number
The group to use when running package scripts in global mode as the root user.
https-proxy
- Default: the
HTTPS_PROXY
orhttps_proxy
orHTTP_PROXY
orhttp_proxy
environment variables. - Type: url
A proxy to use for outgoing https requests.
user-agent
- Default: node/{process.version} {process.platform} {process.arch}
- Type: String
Sets a User-Agent to the request header
ignore
- Default: ""
- Type: string
A white-space separated list of glob patterns of files to always exclude from packages when building tarballs.
init-module
- Default: ~/.npm-init.js
- Type: path
A module that will be loaded by the
npm init
command. See the documentation for the init-package-json
module for more information, or npm-init(1).
init.version
- Default: "0.0.0"
- Type: semver
The value
npm init
should use by default for the package version.
init.author.name
- Default: ""
- Type: String
The value
npm init
should use by default for the package author's name.
init.author.email
- Default: ""
- Type: String
The value
npm init
should use by default for the package author's email.
init.author.url
- Default: ""
- Type: String
The value
npm init
should use by default for the package author's homepage.
json
- Default: false
- Type: Boolean
Whether or not to output JSON data, rather than the normal output.
This feature is currently experimental, and the output data
structures for many commands is either not implemented in JSON
yet, or subject to change. Only the output from
npm ls --json
is currently valid.
link
- Default: false
- Type: Boolean
If true, then local installs will link if there is a suitable globally installed package.
Note that this means that local installs can cause things to be installed into the global space at the same time. The link is only done if one of the two conditions are met:
- The package is not already installed globally, or
- the globally installed version is identical to the version that is being installed locally.
loglevel
- Default: "http"
- Type: String
- Values: "silent", "win", "error", "warn", "http", "info", "verbose", "silly"
What level of logs to report. On failure, all logs are
written to
npm-debug.log
in the current working directory.
Any logs of a higher level than the setting are shown. The default is "http", which shows http, warn, and error output.
logstream
- Default: process.stderr
- Type: Stream
This is the stream that is passed to the npmlog module at run time.
It cannot be set from the command line, but if you are using npm programmatically, you may wish to send logs to somewhere other than stderr.
If the
color
config is set to true, then this stream will receive colored
output if it is a TTY.
long
- Default: false
- Type: Boolean
Show extended information in
npm ls
message
- Default: "%s"
- Type: String
Commit message which is used by
npm version
when creating version commit.
Any "%s" in the message will be replaced with the version number.
node-version
- Default: process.version
- Type: semver or false
The node version to use when checking package's "engines" hash.
npat
- Default: false
- Type: Boolean
Run tests on installation and report results to the
npaturl
.
npaturl
- Default: Not yet implemented
- Type: url
The url to report npat test results.
onload-script
- Default: false
- Type: path
A node module to
require()
when npm loads. Useful for programmatic usage.
optional
- Default: true
- Type: Boolean
Attempt to install packages in the
optionalDependencies
hash. Note that if these packages fail to install, the overall
installation process is not aborted.
parseable
- Default: false
- Type: Boolean
Output parseable results from commands that write to standard output.
prefix
- Default: see npm-folders(5)
- Type: path
The location to install global items. If set on the command line, then it forces non-global commands to run in the specified folder.
production
- Default: false
- Type: Boolean
Set to true to run in "production" mode.
- devDependencies are not installed at the topmost level
when running local
npm install
without any arguments. - Set the NODE_ENV="production" for lifecycle scripts.
proprietary-attribs
- Default: true
- Type: Boolean
Whether or not to include proprietary extended attributes in the tarballs created by 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:
HTTP_PROXY
orhttp_proxy
environment variable, or null - Type: url
A proxy to use for outgoing http requests.
rebuild-bundle
- Default: true
- Type: Boolean
Rebuild bundled dependencies after installation.
registry
- Default: https://registry.npmjs.org/
- Type: url
The base URL of the npm package registry.
rollback
- Default: true
- Type: Boolean
Remove failed installs.
save
- Default: false
- Type: Boolean
Save installed packages to a package.json file as dependencies.
When used with the
npm rm
command, it removes it from the dependencies hash.
Only works if there is already a package.json file present.
save-bundle
- Default: false
- Type: Boolean
If a package would be saved at install time by the use of
--save
,
--save-dev
, or
--save-optional
, then also put it in the
bundleDependencies
list.
When used with the
npm rm
command, it removes it from the bundledDependencies list.
save-dev
- Default: false
- Type: Boolean
Save installed packages to a package.json file as devDependencies.
When used with the
npm rm
command, it removes it from the devDependencies hash.
Only works if there is already a package.json file present.
save-optional
- Default: false
- Type: Boolean
Save installed packages to a package.json file as optionalDependencies.
When used with the
npm rm
command, it removes it from the devDependencies hash.
Only works if there is already a package.json file present.
searchopts
- Default: ""
- Type: String
Space-separated options that are always passed to search.
searchexclude
- Default: ""
- Type: String
Space-separated options that limit the results from search.
searchsort
- Default: "name"
- Type: String
- Values: "name", "-name", "date", "-date", "description", "-description", "keywords", "-keywords"
Indication of which field to sort search results by. Prefix with
a
-
character to indicate reverse sort.
shell
- Default: SHELL environment variable, or "bash" on Posix, or "cmd" on Windows
- Type: path
The shell to run for the
npm explore
command.
shrinkwrap
- Default: true
- Type: Boolean
If set to false, then ignore
npm-shrinkwrap.json
files when installing.
sign-git-tag
- Default: false
- Type: Boolean
If set to true, then the
npm version
command will tag the version using
-s
to add a signature.
Note that git requires you to have set up GPG keys in your git configs for this to work properly.
strict-ssl
- Default: true
- Type: Boolean
Whether or not to do SSL key validation when making requests to the registry via https.
See also the
ca
config.
tag
- Default: latest
- Type: String
If you ask npm to install a package and don't tell it a specific version, then it will install the specified tag.
Also the tag that is added to the package@version specified by
the
npm tag
command, if no explicit tag is given.
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: true
- 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(1)
.
user
- Default: "nobody"
- Type: String or Number
The UID to set to when running package scripts as root.
username
- Default: null
- Type: String
The username on the npm registry. Set with
npm adduser
userconfig
- Default: ~/.npmrc
- Type: path
The location of user-level configuration settings.
userignorefile
- Default: ~/.npmignore
- Type: path
The location of a user-level ignore file to apply to all packages.
If not found, but there is a .gitignore file in the same directory, then that will be used instead.
umask
- Default: 022
- Type: Octal numeric string
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.
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
hash, 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.
yes
- Default: null
- Type: Boolean or null
If set to
null
, then prompt the user for responses in some circumstances.
If set to
true
, then answer "yes" to any prompt. If set to
false
then answer "no" to any prompt.