Safeguard
Developer Tools•

Which npmrc files does npm read, and which one wins?

npm reads four npmrc files: project, user, global and built-in. How to see which one sets a value, and why a stray registry line can reroute installs.

Safeguard Security Team
3 min read

npm reads four npmrc files: the project .npmrc, the per user $HOME/.npmrc, a global file under the install prefix, and a built-in one shipped with npm. They are merged, and a user setting overrides the same setting in the global file. Run npm config ls -l to see the result.

The four files

FilePathNotes
Per project.npmrc next to package.jsonNot read in global mode, such as npm install -g
Per user$HOME/.npmrcLocation can be changed with the userconfig setting
Global$PREFIX/etc/npmrcLocation can be changed with globalconfig
Built inInside the npm installCannot be changed; meant for distribution maintainers

The npm documentation gives one precedence example, that user config overrides global config, and does not list the full order on that page. So do not guess. Ask npm.

How to see where a value comes from

  1. Run npm config ls -l to list effective settings.
  2. Run npm config get registry to see which registry will serve installs.
  3. Open the project .npmrc and your home .npmrc side by side.

Treat any unexpected line as a finding, especially registry, ignore-scripts, strict-ssl and anything with auth in its name.

Why a project .npmrc deserves review

A .npmrc in a cloned repository is read automatically when you run npm inside it. That is normal and useful, because teams use it to point at a private registry. It also means a repository can influence how your install behaves. Before running an install in a repo you do not control, read its .npmrc first.

A habit worth adopting

After cloning an unfamiliar repository, make reading its .npmrc part of your routine, right next to reading package.json scripts. It takes a few seconds. Then run npm config get registry inside the folder and confirm the answer is the registry you expect. Teams that do this catch typos in registry hostnames and leftover test settings before an install runs.

Credentials in npmrc

The npm documentation says auth settings must be scoped to a specific registry, which "ensures that npm will never send credentials to the wrong host". It also shows an unscoped _authToken as a bad config. Keep these rules:

  • Scope every token line to its registry.
  • Do not commit tokens. Use an environment variable reference in the project file and keep the real value in your user file or a secret store.
  • Use tokens with the narrowest permission that works, and remove old ones.

Related: npmrc scoped registry and token scoping, and npm ignore scripts on a developer machine.

Safeguard scans dependencies and produces an SBOM for npm projects, whichever registry they came from. Try a free scan at gold.safeguard.sh/scan.

Quick check

Does the project npmrc apply when I install a tool globally?

No. The npm documentation says the per project file is not read in global mode.

Can a project npmrc change my registry?

Yes, for installs run inside that project. Read it before you install in an unfamiliar repository.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.