Set Up your Client’s npmrc Using Azure Artifacts Token on Windows
Azure DevOps artifacts authentication using npmrc files on a windows PC
Azure Artifacts requires authentication for you to install or publish npm packages hosted in Azure DevOps. Today we will take a look at how we can set up this authentication using an npmrc configuration file.
An npmrc file contains configuration settings that npm uses. And it bears the name .npmrc.
Get credentials from Azure
To get started, login into your Azure DevOps account, select any project and then click on Artifacts. Then select Connect to feed.
After clicking on Connecting to feed you will be presented with several package management tools.
Select npm because that is what we are looking at in this article.
Installing artifacts credentials provider.
Before you proceed further, make sure you install the credentials provider npm package globally by running the following command in your terminal.
npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false
Note: In case you don’t have Node.js and npm installed on your PC. Please follow this guide.
Creating an npmrc config file
Now, on your PC, create a file name .npmrc in your projects root folder. That is, in the same directory where you have the package.json file.
From your DevOps copy and paste the two lines of code specifying your registry URL and whether authentication should always be on. The lines are highlighted in red in the figure below.
Finally, on your PC, within the projects root folder run the following command:
vsts-npm-auth -config .npmrc
You can now successfully restore packages or publish packages to azure DevOps.
To restore packages, run this command in your projects root folder.
To publish a package, run this command in your projects root folder