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?
By default NPM—the Node Package Manager—uses its own public registry (at https://registry.npmjs.org) to pull down packages when you run npm install or npm update inside of a project. You can specify different registries at multiple levels or scopes to override these default value (and other configuration settings).
npmrc Files Per-project config file: /path/to/my/project/. npmrc. Per-user config file: ~/. npmrc.
You can use the npm config command to update and edit the contents of the user and global npmrc files. Npmrc has four relevant files, they are: The per-project config file (/path/to/my/project/.
First, we have to tell npm where to find our private registry. Since every project can have it’s own private registry it’s a good practice to create a .npmrc file inside your project. We tell npm to use the http://private.acme.com registry for all packages with the @private scope.
The npm config command can be used to update and edit the contents of the user and global npmrc files. For a list of available configuration options, see config. The four relevant files are: All npm config files are an ini-formatted list of key = value parameters. Environment variables can be replaced using $ {VARIABLE_NAME}. For example:
Lines in .npmrc files are interpreted as comments when they begin with a ; or # character. .npmrc files are parsed by npm/ini, which specifies this comment syntax. When working locally in a project, a .npmrc file in the root of the project (ie, a sibling of node_modules and package.json) will set config values specific to this project.
npm gets its config settings from the command line, environment variables, and npmrc files. The npm config command can be used to update and edit the contents of the user and global npmrc files. For a list of available configuration options, see config. The four relevant files are:
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With