MadCatm2
MadCatm2

Reputation: 1001

Configure multiple registries in .npmrc

I am able to publish and install packages from my internal/private registry by configuring my .npmrc like so:

  $ npm config set registry https://mynpm-registry.com

However, I would like to configure my .npmrc to proxy out to public https://registry.npmjs.com/, if the package is not available in my internal regisry.

I understand that I can potentially configure multiple npm profiles - one for internal and one for external registry - like so:

$ npmrc -c my-internal-profile
$ npmrc -c my-external-profile

...but this is not what I am looking for. I would like to have a single .npmrc configuration, with both registries, that will proxy out to the public registry if I don't have a package available in my internal registry.

Is there anyway to do this?

Upvotes: 10

Views: 26649

Answers (1)

Sujil Maharjan
Sujil Maharjan

Reputation: 1377

One way you could do it is scoped packages in your .npmrc file.

Scoped Packages are simply put as the packages grouped under a namespace. You might have seen @angular/core or @react/something. So, these are the scoped packages.

In your .npmrc file, you could do the following

@yourorg:registry=http://localhost:4040/
registry=https://registry.npmjs.com

So, this basically means that you everything under @yourorg will be received from your registry, but others are going to be fetched from registry.npmjs.org.


If the first option doesn't solve what you are trying to do, you should look into https://help.sonatype.com/repomanager3/download

This is a registry manager where you can create private registries and create a group of registries (where one of them could be https://registry.npmjs.org). Then for npm, it would look like just a regular call but Sonatype does the heavylifting of :

  • If not found in your private registry, it looks to another registry you have mentioned.

Upvotes: 17

Related Questions