Commands for managing npm configuration settings, authentication, and environment setup.
Manage npm configuration settings and options.
/**
* Set configuration values
* @param key - Configuration key
* @param value - Configuration value
* @param --global - Set in global config file
* @param --location - Config file location ('global', 'user', 'project')
*/
npm config set <key> <value>
npm config set <key> <value> --global
npm config set <key> <value> --location=project
/**
* Get configuration values
* @param key - Configuration key to retrieve
* @param --global - Get from global config
* @param --json - Output in JSON format
*/
npm config get <key>
npm config get <key> --global
npm config get registry --json
/**
* Delete configuration values
* @param key - Configuration key to delete
* @param --global - Delete from global config
*/
npm config delete <key>
npm config delete <key> --global
/**
* List all configuration settings
* @param --json - Output in JSON format
* @param --global - Show only global config
* @param --long - Show all config including defaults
*/
npm config list
npm config ls
npm config list --json
npm config list --global
npm config list --long
/**
* Edit configuration file in default editor
* @param --global - Edit global config file
*/
npm config edit
npm config edit --global
/**
* Fix configuration permissions and ownership
*/
npm config fixUsage Examples:
# Set configuration values
npm config set registry https://registry.npmjs.org/
npm config set init-author-name "John Doe"
npm config set save-exact true --global
# Get configuration values
npm config get registry
npm config get init-author-email
# List all configuration
npm config list
npm config list --json
# Edit configuration file
npm config editImportant npm configuration options:
# Registry and authentication
registry=<registry-url> # Default registry URL
<registry-host>/:_authToken=<token> # Authentication token for registry
always-auth=<true|false> # Always authenticate requests
# Package installation
save=<true|false> # Save to package.json by default
save-dev=<true|false> # Save to devDependencies by default
save-exact=<true|false> # Save exact versions instead of ranges
save-prefix=<prefix> # Version prefix for saved packages
global-style=<true|false> # Install packages globally-style locally
legacy-peer-deps=<true|false> # Use legacy peer dependency resolution
strict-peer-deps=<true|false> # Fail on peer dependency conflicts
# Cache and performance
cache=<path> # Cache directory location
offline=<true|false> # Use only cached packages
prefer-offline=<true|false> # Use cache when available
prefer-online=<true|false> # Skip cache, always fetch
maxsockets=<number> # Maximum concurrent connections
# Scripts and hooks
ignore-scripts=<true|false> # Skip package lifecycle scripts
script-shell=<path> # Shell for running scripts
node-options=<options> # Node.js options for scripts
# Package metadata
init-author-name=<name> # Default author name for npm init
init-author-email=<email> # Default author email for npm init
init-license=<license> # Default license for npm init
init-version=<version> # Default version for npm init
# Logging and output
loglevel=<level> # Log level ('silent', 'error', 'warn', 'notice', 'http', 'timing', 'info', 'verbose', 'silly')
progress=<true|false> # Show progress bars
color=<true|false> # Use colors in output
unicode=<true|false> # Use unicode charactersManage user authentication and credentials.
/**
* Interactive login to registry
* @param --registry - Registry URL to login to
* @param --scope - Scope for scoped packages
* @param --auth-type - Authentication type ('legacy', 'oauth', 'saml', 'sso')
*/
npm login
npm adduser
npm login --registry=<registry-url>
npm login --scope=@myorg
/**
* Logout from registry
* @param --registry - Registry URL to logout from
* @param --scope - Scope to logout from
*/
npm logout
npm logout --registry=<registry-url>
/**
* Show current authenticated user
* @param --registry - Registry URL to check
*/
npm whoami
npm whoami --registry=<registry-url>Usage Examples:
# Login to npm registry
npm login
# Login to private registry
npm login --registry=https://npm.mycompany.com/
# Login for scoped packages
npm login --scope=@myorg
# Check current user
npm whoami
npm whoami --registry=https://npm.mycompany.com/
# Logout
npm logoutManage authentication tokens for registry access.
/**
* List authentication tokens
* @param --json - Output in JSON format
* @param --parseable - Output in parseable format
* @param --registry - Registry URL
*/
npm token list
npm token ls
npm token list --json
/**
* Create new authentication token
* @param --read-only - Create read-only token
* @param --cidr - CIDR range restriction
* @param --registry - Registry URL
*/
npm token create
npm token create --read-only
npm token create --cidr=192.168.1.0/24
/**
* Revoke authentication token
* @param id - Token ID to revoke
* @param --registry - Registry URL
*/
npm token revoke <id>Usage Examples:
# List tokens
npm token list
# Create new token
npm token create
npm token create --read-only
# Revoke token
npm token revoke abcd1234Commands for setting up and diagnosing npm environment.
/**
* Run environment diagnostics
* Check npm environment for common issues
*/
npm doctor
/**
* Display npm environment information
* @param --json - Output in JSON format
*/
npm config list
npm config getUsage Examples:
# Check npm health
npm doctor
# Show all environment info
npm config list --longConfiguration options for npm workspaces in monorepos.
# Workspace-specific configuration
workspaces=<true|false> # Enable workspace features
workspace=<workspace-name> # Operate on specific workspace
workspaces-update=<true|false> # Update workspace dependencies
# Workspace root configuration in package.json
{
"workspaces": [
"packages/*",
"apps/*"
]
}Usage Examples:
# Enable workspaces
npm config set workspaces true
# Install in specific workspace
npm install express --workspace=api
# Run command in all workspaces
npm run test --workspacesConfigure npm to work with multiple registries.
/**
* Default registry configuration
*/
npm config set registry https://registry.npmjs.org/
/**
* Scoped registry configuration
* @param scope - Package scope
* @param registry-url - Registry URL for the scope
*/
npm config set @myorg:registry https://npm.myorg.com/
/**
* Authentication for private registry
* @param registry-host - Registry hostname
* @param token - Authentication token
*/
npm config set //npm.myorg.com/:_authToken <token>
/**
* Certificate configuration for private registries
*/
npm config set ca <certificate-content>
npm config set cafile <path-to-ca-file>
npm config set strict-ssl falseUsage Examples:
# Set default registry
npm config set registry https://registry.npmjs.org/
# Set scoped registry
npm config set @mycompany:registry https://npm.mycompany.com/
# Set authentication token
npm config set //npm.mycompany.com/:_authToken abc123def456
# Disable SSL verification (not recommended)
npm config set strict-ssl falsenpm uses multiple configuration files in priority order:
# Configuration file priority (highest to lowest)
1. Command line flags: --registry=<url>
2. Environment variables: NPM_CONFIG_REGISTRY=<url>
3. .npmrc in project directory
4. .npmrc in user home directory (~/.npmrc)
5. Global .npmrc (/usr/local/etc/npmrc)
6. Built-in defaultsProject .npmrc example:
registry=https://npm.mycompany.com/
@myorg:registry=https://npm.mycompany.com/
//npm.mycompany.com/:_authToken=${NPM_TOKEN}
save-exact=true
engine-strict=trueGlobal .npmrc example:
init-author-name=John Doe
init-author-email=john@example.com
init-license=MIT
save-exact=true
progress=truenpm configuration can be set via environment variables:
# Environment variable format: NPM_CONFIG_<config-key>
NPM_CONFIG_REGISTRY=<registry-url>
NPM_CONFIG_CACHE=<cache-directory>
NPM_TOKEN=<authentication-token>
NODE_ENV=<environment>
NPM_CONFIG_LOGLEVEL=<log-level>
NPM_CONFIG_PROGRESS=<true|false>Usage Examples:
# Set registry via environment variable
export NPM_CONFIG_REGISTRY=https://npm.mycompany.com/
# Set token via environment variable
export NPM_TOKEN=abc123def456
# Run with specific configuration
NPM_CONFIG_LOGLEVEL=verbose npm install