Edit

Publish and download npm packages with Azure Artifacts

Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022

Azure Artifacts enables developers to publish and download npm packages from feeds or public registries.

This article guides you through creating a feed, configuring your project, and publishing and downloading npm packages.

Prerequisites

Create a feed

  1. Sign in to your Azure DevOps organization and navigate to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Enter a Name for your feed.

  4. Choose a Visibility setting to control who can view packages in the feed.

  5. Select Include packages from common public sources if you want your feed to use upstream packages from sources such as nuget.org or npmjs.com.

  6. For Scope, choose whether the feed is scoped to the current project or the entire organization.

  7. Select Create when you're done.

    Screenshot showing selections for creating a new feed in Azure DevOps Services.

  1. Sign in to your Azure DevOps server, and then go to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Enter a Name for your feed.

  4. Choose a Visibility setting to control who can view packages in the feed.

  5. Select Include packages from common public sources if you want your feed to use upstream packages from sources such as nuget.org or npmjs.com.

  6. For Scope, choose whether the feed is scoped to the current project or the entire organization.

  1. Select Create when you're done.

    Screenshot showing selections for creating a new feed in Azure DevOps 2022.

Note

When you create a feed, the project's Build Service account, such as projectName Build Service (orgName), is assigned the Feed and Upstream Reader (Collaborator) role by default.

Set up npm authentication

Before you connect to a feed, set up authentication for the npm client on your machine. The steps differ depending on your operating system:

Windows

Install vsts-npm-auth, which generates and refreshes the credentials npm uses to connect to your Azure Artifacts feed.

npm install -g vsts-npm-auth --registry https://registry.npmjs.com

macOS and Linux

vsts-npm-auth isn't supported on macOS or Linux. Instead, create a personal access token (PAT) with Packaging > Read & write scope. Use that PAT when you configure your user-level .npmrc file in the next section.


Connect to a feed

Azure Artifacts recommends using two separate configuration files. The first should be kept locally in the $HOME directory (Linux/macOS) or $env.HOME (Windows) to securely store your credentials. This allows the npm client to access your credentials for authentication.

By using this setup, you can share project configuration with your team without exposing credentials in source control. For more details, see Connect to an Azure Artifacts feed - npm.

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, select your feed from the dropdown menu, and then select Connect to feed.

  3. Select npm from the left navigation pane.

  4. Under Project setup, select Windows or Other for your operating system, and then follow the provided instructions to update your user-level and project-level .npmrc files.

    Screenshot showing how to set up an npm project and connect to a feed in Azure DevOps Services.

Note

The vsts-npm-auth is not supported in Azure DevOps Server.

  1. Sign in to your Azure DevOps collection, and then navigate to your project.

  2. Select Artifacts, select your feed from the dropdown menu, and then select Connect to feed.

  3. Select npm from the left navigation pane.

  4. Under Project setup, select Windows or Other for your operating system, and then follow the provided instructions to update your user-level and project-level .npmrc files.

    Screenshot showing how to set up an npm project and connect to an Azure Artifacts feed in Azure DevOps Server 2022.

Important

npm supports only a single registry setting in your .npmrc file. If you need packages from multiple sources, use upstream sources or scopes instead of adding multiple registry entries.

Publish packages to your feed

Note

To publish packages to a feed, you must be a Feed Publisher (Contributor) or higher. See Manage permissions for more details.

Before you publish packages, ensure you authenticate with your feed. If you haven't done this yet, follow the steps in the Connect to a feed section, and then continue with the instructions in the following section.

  1. In your project directory, run the following command to publish the package defined in your package.json file to your feed:

    npm publish
    

Important

Using the publishConfig property to override the registry configuration at publish time is not supported.

Restore packages from your feed

Before you restore packages, ensure you authenticate with your feed and update the .npmrc files for your project. If you haven't done this yet, complete the steps in Connect to a feed, and then continue.

  1. In your project directory, run the following command to restore all packages listed in your package.json file:

    npm install
    
  2. To install a specific package from the feed and add it as a dependency in your package.json file, run the following command:

    npm install --save <PACKAGE_NAME>