Get npm Configuration File Location

Get npm Configuration File Location

When working with Node.js and npm, you may encounter situations where certain configuration values don't behave as expected. This usually happens because npm reads configs from multiple locations, and higher-precedence files override lower ones. Knowing where npm stores its config files is the first step to debugging and customizing the setup. This tutorial explains how to get npm configuration file location.

Project-level config

The project-level config is stored in the project's root directory as .npmrc. If present, this file will override user, global, and built-in configurations.

<project_directory>/.npmrc

User-level config

The user-level config is stored in the user's home directory and applies to all projects run by that user. This file overrides global and built-in configurations. To get file location, use the following command:

npm config get userconfig

Example output:

/home/ubuntu/.npmrc

Global/system-level config

The global or system-level config applies to all users and projects on the system. This file overrides built-in configuration. To get file location, run the following command:

npm config get globalconfig

Example output:

/usr/etc/npmrc

Built-in config

The npm comes with a built-in default configuration file that contains the default values for all npm settings. This file is located inside npm installation directory.

npm root -g

Example output:

/usr/lib/node_modules

In this case, the built-in config file can be found at either:

/usr/lib/node_modules/npm/npmrc
/usr/lib/node_modules/npm/.npmrc

Leave a Comment

Cancel reply

Your email address will not be published.