npm-config

管理 npm 配置文件

选择命令行版本:

概要

🌐 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.

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

🌐 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...]

将每个配置键设置为提供的值。

🌐 Sets each of the config keys to the value provided.

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

🌐 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

  • 默认:否
  • 类型:布尔

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

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

  • npm pkg set 中,它可以在将值保存到你的 package.json 之前使用 JSON.parse() 解析设置的值。

并非所有 npm 命令都支持。

🌐 Not supported by all npm commands.

global

  • 默认:否
  • 类型:布尔

以“全局”模式运行,因此软件包会安装到 prefix 文件夹中,而不是当前工作目录。有关行为差异的更多信息,请参见 folders

🌐 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 文件夹中,而不是当前工作目录。
  • bin 文件与 {prefix}/bin 关联
  • 手册页已链接到 {prefix}/share/man

editor

  • 默认:EDITOR 或 VISUAL 环境变量,或在 Windows 上为 '%SYSTEMROOT%\notepad.exe',在 Unix 系统上为 'vi'
  • 类型:字符串

运行 npm editnpm config edit 的命令。

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

location

  • 默认值:除非传入 --global,否则为 "user",传入后该值也会设置为 "global"
  • 类型:“全局”、“用户”或“项目”

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

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

当设置为“全局”模式时,软件包会安装到 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 文件夹中,而不是当前工作目录。
  • bin 文件与 {prefix}/bin 关联
  • 手册页已链接到 {prefix}/share/man

long

  • 默认:否
  • 类型:布尔

lssearchhelp-search 中显示扩展信息。

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

也可以看看

🌐 See Also