Konstantin Dinev
Konstantin Dinev

Reputation: 34915

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

Upvotes: 22

Views: 26681

Answers (3)

Ben Stickley
Ben Stickley

Reputation: 2120

What you seek exists with the --location project option. See below:

npm config --location project set registry https://private.registry.endpoint

Upvotes: 6

G2.0
G2.0

Reputation: 107

I was facing the issue. Solved it by putting a .npmrc file in the project root and assign the desired registry.

Upvotes: 5

Konstantin Dinev
Konstantin Dinev

Reputation: 34915

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

Upvotes: 16

Related Questions