← Back to Node.js Course | Chapter 3: npm & Packages | Lesson 7 of 7

.npmrc

.npmrc is a small config file that changes how npm behaves, such as the registry or auth tokens.

In this page:

  1. .npmrc
Syntax
javascript
registry=https://registry.example.com/
save-exact=true
fund=false

.npmrc

npm reads .npmrc from the project, your home directory and globally, with the project file taking priority. Common settings include registry, save-exact and scoped registries.

Never commit files containing auth tokens; use environment variables in them instead.

Note: Use ${NPM_TOKEN} placeholders in .npmrc and set the variable in CI.

Example: .npmrc

bash
# .npmrc
registry=https://registry.npmjs.org/
save-exact=true
@mycompany:registry=https://npm.mycompany.com/
//npm.mycompany.com/:_authToken=${NPM_TOKEN}

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
Common Mistakes
  1. Committing auth tokens
  2. Editing the global file when a project one is intended
  3. Forgetting scope-specific registries
Chapter Summary
  • .npmrc configures npm
  • Project file overrides user file
  • Store tokens in env variables
  • Scopes can point to private registries
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.