npm-config

管理 npm 配置文件

选择 CLI 版本:

概要

¥Synopsis

npm config set <key>=<value> [<key>=<value> ...]
npm config get [<key> [<key> ...]]
npm config delete <key> [<key> ...]
npm config list [--json]
npm config edit
npm config fix
alias: c

注意:此命令对工作区无感知。

¥Note: This command is unaware of workspaces.

描述

¥Description

npm 从命令行、环境变量、npmrc 文件以及在某些情况下从 package.json 文件获取其配置设置。

¥npm gets its config settings from the command line, environment variables, npmrc files, and in some cases, the package.json file.

有关 npmrc 文件的更多信息,请参见 npmrc

¥See npmrc for more information about the npmrc files.

有关所涉及机制的更详尽解释,以及可用配置选项的完整列表,请参阅 配置

¥See config for a more thorough explanation of the mechanisms involved, and a full list of config options available.

npm config 命令可用于更新和编辑用户和全局 npmrc 文件的内容。

¥The npm config command can be used to update and edit the contents of the user and global npmrc files.

子命令

¥Sub-commands

Config 支持以下子命令:

¥Config supports the following sub-commands:

set

npm config set key=value [key=value...]
npm set key=value [key=value...]

将每个配置键设置为提供的值。修改用户配置文件,除非传递 location

¥Sets each of the config keys to the value provided. Modifies the user configuration file unless location is passed.

如果省略值,则密钥将从你的配置文件中完全删除。

¥If value is omitted, the key will be removed from your config file entirely.

注意:为了向后兼容,支持 npm config set key value 作为 npm config set key=value 的别名。

¥Note: for backwards compatibility, npm config set key value is supported as an alias for npm config set key=value.

get

npm config get [key ...]
npm get [key ...]

将配置值回显到标准输出。

¥Echo the config value(s) to stdout.

如果提供了多个键,则值将以键名作为前缀。

¥If multiple keys are provided, then the values will be prefixed with the key names.

如果未提供任何键,则此命令的行为与 npm config list 相同。

¥If no keys are provided, then this command behaves the same as npm config list.

list

npm config list

显示所有配置设置。使用 -l 也可以显示默认值。使用 --json 以 json 格式显示设置。

¥Show all the config settings. Use -l to also show defaults. Use --json to show the settings in json format.

delete

npm config delete key [key ...]

从所有配置文件中删除指定的键。

¥Deletes the specified keys from all configuration files.

edit

npm config edit

在编辑器中打开配置文件。使用 --global 标志来编辑全局配置。

¥Opens the config file in an editor. Use the --global flag to edit the global config.

fix

npm config fix

尝试修复无效的配置项。通常这意味着将身份验证配置(即 _auth_authToken)附加到配置的 registry

¥Attempts to repair invalid configuration items. Usually this means attaching authentication config (i.e. _auth, _authToken) to the configured registry.

配置

¥Configuration

json

  • 默认值:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

是否输出 JSON 数据,而不是正常输出。

¥Whether or not to output JSON data, rather than the normal output.

  • npm pkg set 中,它可以使用 JSON.parse() 解析集合值,然后再将它们保存到你的 package.json

    ¥In npm pkg set it enables parsing set values with JSON.parse() before saving them to your package.json.

并非所有 npm 命令都支持。

¥Not supported by all npm commands.

global

  • 默认值:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

在 "global" 模式下运行,以便将包安装到 prefix 文件夹而不是当前工作目录。有关行为差异的更多信息,请参见 文件夹

¥Operates in "global" mode, so that packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.

  • 包安装到 {prefix}/lib/node_modules 文件夹,而不是当前工作目录。

    ¥packages are installed into the {prefix}/lib/node_modules folder, instead of the current working directory.

  • bin 文件链接到 {prefix}/bin

    ¥bin files are linked to {prefix}/bin

  • 手册页链接到 {prefix}/share/man

    ¥man pages are linked to {prefix}/share/man

editor

  • 默认值:EDITOR 或 VISUAL 环境变量,或 Windows 上的 '%SYSTEMROOT%\notepad.exe',或 Unix 系统上的 'vi'

    ¥Default: The EDITOR or VISUAL environment variables, or '%SYSTEMROOT%\notepad.exe' on Windows, or 'vi' on Unix systems

  • 类型:字符串

    ¥Type: String

npm editnpm config edit 运行的命令。

¥The command to run for npm edit and npm config edit.

location

  • 默认值:"user" 除非传递 --global,否则也会将此值设置为 "global"

    ¥Default: "user" unless --global is passed, which will also set this value to "global"

  • 类型:"global"、"user" 或 "project"

    ¥Type: "global", "user", or "project"

当传递给 npm config 时,这指的是要使用的配置文件。

¥When passed to npm config this refers to which config file to use.

当设置为 "global" 模式时,包将安装到 prefix 文件夹而不是当前工作目录。有关行为差异的更多信息,请参见 文件夹

¥When set to "global" mode, packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.

  • 包安装到 {prefix}/lib/node_modules 文件夹,而不是当前工作目录。

    ¥packages are installed into the {prefix}/lib/node_modules folder, instead of the current working directory.

  • bin 文件链接到 {prefix}/bin

    ¥bin files are linked to {prefix}/bin

  • 手册页链接到 {prefix}/share/man

    ¥man pages are linked to {prefix}/share/man

long

  • 默认值:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

lssearchhelp-search 中显示扩展信息。

¥Show extended information in ls, search, and help-search.

也可以看看

¥See Also

npm 中文网 - 粤ICP备13048890号