Install NPM dependencies from multiple registries
TL;DR: Add this line to your .npmrc
file
By default, npm install
loads all dependencies defined in package.json
from the npm package registry. However, you may encounter projects that depend on packages published to a private registry.
You can configure npm install
to load public dependencies from the npm package registry and private dependencies from a private registry in a single project by following the step mentioned in the TL;DR above.
Let’s say your package.json
looks like this:
and your .npmrc
is as follows:
npm install
will download react
from the public npm registry and @rayhannr/validator
from rayhannr private registry.
If the private dependencies’ names do not start with @{scope}
, you may need to update the .npmrc
file as follows:
This configuration instructs npm install
to load all dependencies from the private registry. Ensure that the private registry you’re pointing to acts as a proxy to the public npm registry, allowing you to download both public and private dependencies.
Note: It needs authorization to load dependencies from the private registry. Make sure to have an access token and pass it to your .npmrc
file, replacing {YOUR_AUTH_TOKEN_HERE}
. I won’t explain the authorization process in this blog.