Is there any way to configure multiple registries in a single npmrc file

Here is my problem. We have a private NPM registry which only works in VPN. I would like to have a fallback registry https://registry.npmjs.org so that when I am out of VPN it works seamlessly.

P.S. Currently I am using npmrc which does a good job in switching between .npmrc files as a workaround


You can have multiple registries for scoped packages in your .npmrc file. For example:

@polymer:registry=<url register A>
registry=http://localhost:4873/

Packages under @polymer scope will be received from https://registry.npmjs.org, but the rest will be received from your local NPM.


On version 4.4.1, if you can change package name, use:

npm config set @myco:registry http://reg.example.com

Where @myco is your package scope.

You can install package in this way:

npm install @myco/my-package

For more info: https://docs.npmjs.com/misc/scope


For anyone looking also for a solution for authentication, I would add on the scoped packages solution that you can have multiple lines in your .npmrc file:

//internal-npm.example.com:8080/:_authToken=xxxxxxxxxxxxxxx
//registry.npmjs.org/:_authToken=yyyyyyyyyy

Each line represents a different NPM registry


Not the best way but If you are using mac or linux even in windows you can set alias for different registries.

##############NPM ALIASES######################
alias npm-default='npm config set registry https://registry.npmjs.org'
alias npm-sinopia='npm config set registry http://localhost:4873/'

I believe the top-voted answer might be outdated. As of June 2021, there is a much easier way to do this using npmrc.

Refer to npm Docs.

1. Install npmrc

To install npmrc, on the command line, run npm i npmrc -g

2. Create your first npm profile

After installing npmrc, you can create a profile to access your custom (maybe company's) registry.

To create an npm Enterprise profile, on the command line, run npmrc -c name-of-profile. For example, to create a profile called "work", run the following command: npmrc -c work

To set an npm Enterprise registry for the profile, run the following command, replacing your-company-registry with the name of your company's npm Enterprise registry:

npm config set registry https://registry.your-company-registry.npme.io/

3. Create a profile for the public npm registry

After you have created your npm Enterprise profile, you can create a second profile for a different registry, such as the public npm registry.

To create a profile for the public registry, on the command line, run npmrc -c name-of-profile. For example, to create a profile called "open-source", run npmrc -c open-source. To set the public registry for your open source profile, run the following command: npm config set registry https://registry.npmjs.org/

4. Switch profiles with npmrc

To switch profiles, on the command line, run the following command, replacing profile-name with the name of your profile:

npmrc profile-name