How To find the .NPMRC File Locations

Having issues locating the .npmrc file? Check this post to get all the locations on Windows, Mac (OSX), and Linux!

Jan 19, 2023 | Read time 5 minutes

๐Ÿ”” Table of contents

Introduction

When working with Node or NPM projects, often you will encounter the need to check the .npmrc file.

The .npmrc file is just a configuration file that stores information for NPM such as the NPM registry Url, the NPM cache location, authentication configurations, and settings to control NPM beviours, etc.

I had to refer to this file a few times to check configuration on my authentication and fetch() settings!

What is the .npmrc file?

One of the most powerful features of NPM CLI is that it is highly configurable. This configurability comes with the use .npmrc file. The RC in .npmrc stands for Runtime Configuration!

We can configure registry urls to even changing the default node_modules folder!

According to the documentation on NPM, the location of this .npmrc file can be in the following:

  • per-project config file (/path/to/my/project/.npmrc)
  • per-user config file (~/.npmrc)
  • global config file ($PREFIX/etc/npmrc)
  • npm builtin config file (/path/to/npm/npmrc)
my-project
|__some-folder
|__.gitignore
|__.npmrc
|__package.json

How to create .NPMRC file

You can create the .npmrc file manually or it is created automattically. With global and npm builtin configuration file, they should be created automattically.

Now for creating npm files under the โ€œuserโ€, we can use the following command:

npm config edit

This will create a per-user config file (~/.npmrc) and open the file up in your text editor.

As an example, in Windows, when we run npm config edit in the command line, a .npmrc file will be created in C:\Users%username%.npmrc.

After the file is created, Notepad will open up to allow you to edit this file!

You can also create this file by using only the command line:

npm config set registry http://my-private-registry.com --location=user

The above command will set the NPM registry in the .npmrc file (per-user config) - if theres no file it will create it

NPMRC file location on Mac

Global NPM config

$PREFIX/etc/npmrc

/usr/local/etc/npmrc

npm config get prefix

Per-user NPM config

~/.npmrc

/Users/johnsmith/.npmrc

Built-in NPM config

/usr/local/bin/npm/npmrc

NPMRC file location on Windows

On Windows (versions Windows 10, 8, 7), the location of each of the .npmrc are as below.

If we run the NPM command to list our configuration, we can see the whole .npmrc and locations on where it resides

npm config ls -l

The above command will result in something like:

_auth = (protected)
...
global = false
global-style = false
globalconfig = "C:\\Users\\UserName\\AppData\\Roaming\\npm\\etc\\npmrc"
heading = "npm"
...
userconfig = "C:\\Users\\UserName\\.npmrc"
version = false
versions = false
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc
prefix = "C:\\Users\\{UserName}\\AppData\\Roaming\\npm"

Global NPM config

C:\Users\%username%\AppData\Roaming\npm\etc\npmrc

Per-user NPM config

C:\Users\%username%\.npmrc

Built-in NPM config

C:\Program Files\nodejs\node_modules\npm\npmrc

Note: Global NPM location for Windows XP

If you are still using Windows XP in 2023, then you can find the global NPM location under:

%USERPROFILE%\AppData\npm\node_modules

NPMRC file location on Linux

Global NPM config

According to the specifications (https://docs.npmjs.com/cli/v8/configuring-npm/npmrc), we can see that they say the path is:

  • global config file ($PREFIX/etc/npmrc)

Ok so this looks great, but what is the $PREFIX?

A PREFIX is the path on your host computer a software package is installed under. So anytime you install a software package, the path with be placed under the PREFIX - the prefix will be the root!

You can configure the prefix yourself, but packages for your host computer typically use a default prefix of /usr/local on FreeBSD and Linux.

So the path will typically be for .npmrc files for Linux:

/usr/local/etc/npmrc

Per-user NPM config

~/.npmrc

Built-in NPM config

/usr/local/lib/node_modules/npmrc

Tip: Use the NPM command line

Instead of noting down where project-level, user-level, global or built in locations of the .npmrc file, you can just use the command line.

As an example you can use npm config edit --location=global. This will open up your default text editor to edit the global .npmrc file

The location flag (โ€“location) can have values of global, user, and local!

Summary

In this article, I went over several places where the NPM configuration file .npmrc is located!

We went over locations for .npmrc file on Windows - keeping in mind the different locations for Windows 10, 7, 8 and even XP.

Locations for OSX (Mac) and Linux are fairly similar - keeping in mind the $PREFIX (check to see if you have overwritten it)

Instead of trying to remember where these .npmrc files are located, it is probably easier to just use the command line to edit the file with npm config edit --location=<global|user|local>.

๐Ÿ‘‹ About the Author

G'day! I am Huy a software engineer based in Australia. I have been creating design-centered software for the last 10 years both professionally and as a passion.

My aim to share what I have learnt with you! (and to help me remember ๐Ÿ˜…)

Follow along on Twitter , GitHub and YouTube