Private npm registry with fallback to global registry

964 Views Asked by At

Installing the npm package from the global registry( https://registry.npmjs.com ), if that package does not exist, install it from Azure Artifacts. To do this:

First I create .npmrc in the root directory where the package.json file is.

registry=http://server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/
//https://registry.npmjs.com/

always-auth=true

; begin auth token
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/:username=DefaultCollection
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/:_password=[XXXXXXX==]
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/:email=npm requires email to be set but doesn't use the value
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/:username=DefaultCollection
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/:_password=[XXXXXXX==]
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

NOTE: We have to replace XXXXXXX with token.

I run the following command to install the express package

npm install express

What I expect is : It has to install the express package from the global registry

When run the following command

npm install cac-common

I expect to install package above from Azure Artifacts(this is my private pakcage.)

But It does not work. where I'm wrong?

Any help would be appreciated.

Thanks in advance.

1

There are 1 best solutions below

2
On

There is one possible solution.

If you set your company/organization packages to have a scope like @mycompany. You can define an .npmrc like this

@mycompany:registry=http://server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/
//https://registry.npmjs.com/

always-auth=true

; begin auth token
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/:username=DefaultCollection
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/:_password=[XXXXXXX==]
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/registry/:email=npm requires email to be set but doesn't use the value
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/:username=DefaultCollection
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/:_password=[XXXXXXX==]
//server/DefaultCollection/CMP/_packaging/Frontend-Feed/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

That way, when you install @mycompany/mypackage; npm will get it from Azure and the rest from the public npm registry.

I hope that works for you...