Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set npm registry only for the specific project

I'm using a private npm registry for one of my npm packages and I also have a couple of other packages referenced from the default npm registry. What I'm doing at the moment is:

npm config set registry https://private.registry.endpoint

However, this changes the registry globally. I can manually create a .npmrc at the root of my project and set the registry manually inside. This does not replace my global registry and uses the private registry only for the specific project. However, I want to do this with a command, instead of having to manually create the .npmrc and set the registry.

In case you're wondering why I need this, I know how to do it myself, however I have to guide other users how to do it, and it would be simpler to just provide a command for them. I need to know if there is a way to do something of the sort:

npm config --local set registry https://private.registry.endpoint
like image 804
Konstantin Dinev Avatar asked Dec 22 '16 12:12

Konstantin Dinev


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 private npm registry?

With npm private packages, you can use the npm registry to host code that is only visible to you and chosen collaborators, allowing you to manage and use private code alongside public code in your projects. Private packages always have a scope, and scoped packages are private by default.


1 Answers

We solved this problem by scoping our private packages, which allows us to add the private registry only for the specific @scope instead of changing the entire default registry to download the private packages.

E.g.

If we have a package named package-name, in our private registry we publish it as @company/package-name and then set the private registry scope to be @company.

npm config set @company:registry https://private.registry.endpoint

like image 157
Konstantin Dinev Avatar answered Sep 28 '22 01:09

Konstantin Dinev