npm-config
Manage npm configuration options
TLDR
Show all configuration settings
List all configuration settings as JSON
Get the value of a specific configuration key
Set a configuration key to a specific value
Delete a configuration key
Edit the global npm configuration file in the default editor
Attempt to repair invalid configuration items
SYNOPSIS
npm config set
npm config get
npm config delete
npm config list [
npm config edit [
npm config fix [
PARAMETERS
--global, -g
Operates on the global configuration file ($PREFIX/etc/npmrc) instead of the user configuration file (~/.npmrc).
--location
Specifies which configuration file level ('project', 'user', or 'global') to modify or query. This option overrides the --global flag.
--long
Used with npm config list to display all configuration values in full, including default values.
--json
Used with npm config list to output configuration values in JSON format.
--editor
Specifies the executable to use as an editor when npm config edit is run. Overrides EDITOR or VISUAL environment variables.
--userconfig
The path to the user's npm configuration file. Overrides the default user config path (~/.npmrc).
--globalconfig
The path to the global npm configuration file. Overrides the default global config path ($PREFIX/etc/npmrc).
DESCRIPTION
The npm config command allows users to get, set, delete, and list the npm configuration values. These configurations control various aspects of npm's behavior, such as proxy settings, registry URL, package installation locations, and more.
Configuration settings can exist at multiple levels: project-specific (./.npmrc), user-specific (~/.npmrc), global ($PREFIX/etc/npmrc), and built-in defaults. When a configuration value is requested, npm resolves it based on this hierarchy, with project-level settings overriding user-level, and user-level overriding global and built-in.
This command is essential for tailoring npm's operations to specific environments or project needs, enabling developers to customize their workflow, manage private registries, or configure network proxies efficiently.
CAVEATS
Setting a configuration value using npm config set without --global or --location global will save it to the user's .npmrc file (~/.npmrc).
Configuration values are read from multiple sources in a specific order of precedence: command line flags, environment variables, project .npmrc, user .npmrc, global .npmrc, and built-in defaults.
Sensitive information like tokens or passwords should be handled with care. Consider using environment variables for such data if possible, or ensure .npmrc files have appropriate permissions.
CONFIGURATION FILE LOCATIONS
Npm configuration can be stored in several .npmrc files. The typical locations are:
Project-level: ./.npmrc (in the current working directory). This is primarily used for project-specific settings that should be committed to version control.
User-level: ~/.npmrc (in the user's home directory). This file stores user-specific settings that apply across all projects for that user.
Global-level: $PREFIX/etc/npmrc (where $PREFIX is typically /usr/local or a Node.js installation directory). This file contains system-wide settings.
Built-in: npm also has a set of default, built-in configurations that serve as a baseline.
PRECEDENCE
When npm resolves a configuration value, it applies a specific order of precedence, with higher levels overriding lower ones:
1. Command-line flags (e.g., --registry=...)
2. Environment variables (e.g., npm_config_registry=...)
3. Project .npmrc file
4. User .npmrc file (~/.npmrc)
5. Global .npmrc file ($PREFIX/etc/npmrc)
6. Built-in defaults
HISTORY
The npm config command is an integral part of the npm (Node Package Manager) utility, which was first released in 2010. As npm evolved to manage a vast ecosystem of Node.js packages, the need for robust and flexible configuration management became paramount. The config subcommand was introduced early in npm's development lifecycle to provide a standardized way for users to customize npm's behavior. Its design reflects the common UNIX philosophy of configuration files, allowing settings to be overridden at different levels (project, user, global) to accommodate diverse development environments and deployment scenarios. Continuous improvements have focused on enhancing clarity, adding new configuration options, and ensuring compatibility across different npm versions.
SEE ALSO
npm(1), npm-install(1), npmrc(5), npm-set-script(1)