DEV Community

Henk van den Brink
Henk van den Brink

Posted on • Edited on

Multi NPM registries usage made easy (Azure DevOps)

The problem

I use Azure DevOps for development and have several projects in it.

And I am using the feeds possibility from Azure DevOps.
This means that I need to change the NPMRC each time I switch projects so that it uses the correct registry.

Or you put that in a .npmrc in the repository but then you need to still handle the authentication somehow...

What?

I thought there must be an easier way.

Inspired by the npmrc project I created my own solution, more tailored for Azure DevOps.

But you should still be able to use it as a npmrc switcher, just like the other package but with some added functionality.
Like an interactive list.

To break it down a bit what it does:

It will create an NPMRC with the provided feed-name as registry AND create a PAT that is allowed to pull data from the artifact feed.
And provide options to automatically renew the PAT.

So how to use it?

Easiest

Only one parameter is required

  • feedName (the name of the Artifact feed as created in Azure DevOps)

Then there are a few defaults:

  • name of the NPMRC (defaults to the directory name)

Next to the name of the NPMRC and the feedname we also need the details of the Azure DevOps Organization and Project.

These two values can be retrieved from the repository.url if that is set in the package.json

  • azOrganization (first part of Azure DevOps url)
  • azProject (second part of Azure DevOps url)

Example Azure DevOps url: https://dev.azure.com/henkvandenbrink/kitchensink

azOrganization = henkvandenbrink

azProject = kitchensink

feedName = As specified

Full example:

snmprc create feed-name

This will generate an NPMRC with the specified feed-name as registry, the azure details are retrieved from package.json and current directory name is used as name.

More details options

When you are not able to use the defaults or you just want to have more control, you can specify all the parameters as well.

snpmrc create feed-name henkvandenbrink kitchensink directory-name

This will generate an NPMRC with the specified feed-name as registry, the azure details that are provided and directory-name is used as name.

For all other options, more information and details please go to the simple-aznpmrcs npmjs package where there is a full readme available.

Feature requested are welcome and/or pull requests.

Just another step into automating those manual steps :)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

DevCycle image

Ship Faster, Stay Flexible.

DevCycle is the first feature flag platform with OpenFeature built-in to every open source SDK, designed to help developers ship faster while avoiding vendor-lock in.

Start shipping

👋 Kindness is contagious

Discover this thought-provoking article in the thriving DEV Community. Developers of every background are encouraged to jump in, share expertise, and uplift our collective knowledge.

A simple "thank you" can make someone's day—drop your kudos in the comments!

On DEV, spreading insights lights the path forward and bonds us. If you appreciated this write-up, a brief note of appreciation to the author speaks volumes.

Get Started