a .npmrc file Explained

What a .npmrc file does, with an example.

Published November 12, 2026

A .npmrc file stores npm configuration as key=value lines: registries, auth tokens, scopes and install behaviour. It exists at project, user and global levels, with project settings overriding user ones.

How it works

Typical uses: pointing a scope at a private registry, setting save-exact, and providing auth tokens from environment variables.

Never commit real tokens; reference environment variables instead.

Try it

cat .npmrc
@mycompany:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
save-exact=true

Practical examples

Private scope

@mycompany:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}

Install behaviour

save-exact=true
engine-strict=true
legacy-peer-deps=true

See effective config

npm config list
npm config get registry

Per user

npm config set registry https://registry.npmjs.org/

Common mistakes

  • Committing auth tokens.
  • Using legacy-peer-deps without understanding the conflict.
  • Forgetting project .npmrc overrides user settings.

Key takeaways

  • A .npmrc file stores npm configuration as key=value lines: registries, auth tokens, scopes and install behaviour.
  • Run npm help <command> for every option.
  • Commit package-lock.json.

FAQ

Where are the files?

Project root, ~/.npmrc (user) and the global prefix etc/npmrc.

Does this work with yarn or pnpm?

They have equivalents with similar commands.

More JavaScript articles