Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define fallback registry in global .npmrc file

Tags:

node.js

I have a private registry configured in my global .npmrc file. Now I want to configure a fallback registry also in the same npmrc file. When npm is not able to find module in my private repository, I want it to download it from npm global registry i.e. https://registry.npmjs.org

Below are the two repositories I want to configure:

http://devint:9999/nexus/content/groups/NPM-Release   //npm should first look into this

https://registry.npmjs.org // fallback registry

I know there is a solution available on StackOverflow for this similar problem, but those solution is suggesting to used scoped package approach. I don't want to use the scoped package approach for configuring multiple repositories in a npmrc file.

I have already gone through the solution available on Is there any way to configure multiple registries in a single npmrc file But I am looking for a different approach, where I can define multiple repositories with its priority in npmrc file.

I request not to mark this question as closed without giving a satisfactory correct answer.

Thanks.

like image 731
user2068260 Avatar asked Dec 18 '17 15:12

user2068260


People also ask

What is registry in Npmrc file?

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).

What is the default npm registry?

The default is typically set to the public npm registry at https://registry.npmjs.org/ . For more information about npm configuration files, see the npm config file documentation.

How do I edit Npmrc files?

The config setting for npm is gotten from the command line, environment variables and the npmrc files. 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/.


1 Answers

As far as I know you can not define multiple NPM registry URLs in .npmrc , on the CLI, or anywhere else, and have NPM check them based on priority.

Configure your NPM server to check for a requested package locally first and fall back to the public NPM registry if not found. This can be done with Nexus, and I believe Sinopia/Verdaccio do this out of the box.

like image 82
Dan O Avatar answered Oct 02 '22 01:10

Dan O