LinuxCommandLibrary

npm-config

Manage npm configuration options

TLDR

Show all configuration settings

$ npm config list
copy

List all configuration settings as JSON
$ npm config list --json
copy

Get the value of a specific configuration key
$ npm config get [key]
copy

Set a configuration key to a specific value
$ npm config set [key]=[value]
copy

Delete a configuration key
$ npm config delete [key]
copy

Edit the global npm configuration file in the default editor
$ npm config edit
copy

Attempt to repair invalid configuration items
$ npm config fix
copy

SYNOPSIS

npm config get []
npm config set
npm config delete
npm config list
npm config edit
npm config cache

PARAMETERS

get []
    Gets the value of the specified configuration key. If no key is specified, it will display all keys.

set
    Sets the value of the specified configuration key. This will override any existing value.

delete
    Deletes the specified configuration key from the configuration file.

list
    Lists all npm configuration settings.

edit
    Opens the configuration file in the default editor for manual editing.

cache
    Manage the npm cache (used rarely now)

-g, --global
    Operates on the global npm configuration rather than the local project configuration.

--location=global
    Operates on the global npm configuration rather than the local project configuration.

--location=project
    Operates on the local project configuration.

--json
    Output results in JSON format.

DESCRIPTION

The `npm config` command is used to manage npm's configuration settings. It allows you to view, set, and delete npm configuration options. These configuration options affect how npm installs packages, resolves dependencies, and performs other operations. The command is invaluable for tailoring npm's behavior to your specific project needs or development environment. You can set configurations globally (affecting all projects) or locally (affecting only the current project).
Configurations stored in different locations override each other based on priority, from command-line arguments to npm defaults. Understanding configuration is essential for efficient npm usage and consistent project builds across different systems.

CAVEATS

Modifying the global configuration can impact all projects on your system. Be mindful of the scope when setting configuration values.

CONFIGURATION FILES

npm reads configuration settings from several locations in order of priority:
1. Command line flags.
2. Environment variables.
3. Project .npmrc file.
4. User .npmrc file (~/.npmrc).
5. Global npmrc file (prefix/etc/npmrc).
6. npm's built-in defaults.

SEE ALSO

npm(1), npm-install(1), npmrc(5)

Copied to clipboard