[FIXED] How to set npm registry only for the specific project

Issue

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

Solution

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

Answered By – Konstantin Dinev

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published