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阅读 162,710评论 4 376
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,839评论 2 308
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 112,295评论 0 255
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,776评论 0 223
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 53,198评论 3 297
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 41,074评论 1 226
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,200评论 2 322
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,986评论 0 214
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,733评论 1 250
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,877评论 2 254
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,348评论 1 265
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,675评论 3 265
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,393评论 3 246
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,209评论 0 9
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,996评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 36,212评论 2 287
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 36,003评论 2 280

推荐阅读更多精彩内容