{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/azure-artifacts-publish-private-npm-package-with-azure-devops",
  "description": "Azure DevOps has a feature called Azure Artifacts that supports publishing npm packages to a feed for consumption. This post shows how to publish a private npm package with Azure DevOps.",
  "path": "/posts/azure-artifacts-publish-private-npm-package-with-azure-devops",
  "publishedAt": "2024-12-01T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "azure devops",
    "node.js"
  ],
  "textContent": "Azure DevOps has a feature called Azure Artifacts that supports publishing npm packages to a feed for consumption. Publishing a private npm package with Azure DevOps is a common scenario for teams that want to share code across projects or organizations. This post shows how to publish a private npm package with Azure DevOps.\n\nPublishing a private npm package with Azure DevOps is fairly straightforward, but surprisingly documentation is a little sparse.\n\n\n\nWhat feeds are available in Azure Artifacts?\n\nIf you don't already have a feed to publish your npm package to, you can create one in Azure DevOps by following these instructions.\n\nIf you're trying to find out what feeds are available in Azure Artifacts, you can find them in the Azure DevOps UI. Go to the Artifacts section in Azure DevOps and you'll see a list of feeds. The URL for the feed will be in the format https://dev.azure.com/[ORGANIZATION]/_artifacts/feed.\n\nThere you'll see a dropdown with the feeds you have access to:\n\nYou'll see from the screenshot that I have access to a feed called npmrc-script-organization. Let's use that feed to publish a private npm package.\n\nSetting up the .npmrc file\n\nSo that you can publish to a private feed, you need to set up an .npmrc file in your project. This file will contain the URL of the feed you want to publish to, and your credentials. To set up the .npmrc file, you can click on the \"Connect to Feed\" button in the Azure DevOps UI:\n\nThen select npm and you'll see the instructions for setting up the .npmrc file:\n\nPublishing with Azure Pipelines\n\nNow we're ready to publish our npm package with Azure DevOps. Here's an example of an Azure Pipelines YAML file that publishes a private npm package:\n\nLet's break down the steps in this YAML file:\n\n- We're installing Node.js and authenticating with the .npmrc file.\n- We're running npm install and npm run build. These are standard steps for building a Node.js project; yours might vary; what's important is that you are able to get your built package set up.\n- Finally, we use the Npm@1 task to publish the package. We specify the publishRegistry as useFeed and the publishFeed as npmrc-script-organization. This is the feed we're publishing to.\n\nConclusion\n\nIn this post, we've seen how to publish a private npm package with Azure DevOps. We've set up the .npmrc file, and we've used an Azure Pipelines YAML file to publish the package. This is a common scenario for teams that want to share code across projects or organizations. I hope this post has been helpful to you!",
  "title": "Azure Artifacts: Publish a private npm package with Azure DevOps"
}