Edit

Share via


Publish and download npm packages with Azure Artifacts

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

With Azure Artifacts, you can publish and download npm packages from both your own feeds and public registries such as npmjs.com. This quickstart guides you through creating a feed, configuring your project, and managing npm packages using Azure Artifacts.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization.
- An Azure DevOps project.
- Download and install Node.js and npm.

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. Provide a Name for your feed, choose the Visibility option that defines who can view your packages, check Include packages from common public sources if you want to include packages from sources like nuget.org or npmjs.com, and for Scope, decide whether the feed should be scoped to your project or the entire organization.

  4. Select Create when you're done.

    Screenshot that shows 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. Provide a Name for your feed, choose the Visibility option that defines who can view your packages, check Include packages from common public sources if you want to include packages from sources like nuget.org or npmjs.com, and for Scope, decide whether the feed should be scoped to your project or the entire organization.

  1. Select Create when you're done.

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

  1. Select Create when you're done.

    Screenshot that shows selections for creating a new feed in Azure DevOps 2020.

Note

By default, the Build Service for the project (for example: projectName Build Service (orgName)) is assigned the Feed and Upstream Reader (Collaborator) role when a new feed is created.

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.

In this section, you'll configure the second npmrc file, which should be placed in the same directory as your package.json file.

This setup lets you share your configuration file without exposing your credentials.

  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. In the left navigation pane, select npm. If this is your first time using Azure Artifacts with npm, make sure you've installed the prerequisites.

  4. Under the Project setup section, select Windows or Other depending on your operating system, then follow the provided instructions to configure your config file and connect to your Azure Artifacts feed.

    A screenshot displaying 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. In the left navigation pane, select npm. If this is your first time using Azure Artifacts with npm, make sure you've installed the prerequisites.

  4. Under the Project setup section, select Windows or Other depending on your operating system, then follow the provided instructions to configure your config file and connect to your Azure Artifacts feed.

    A screenshot displaying how to set up an npm project and connect to an Azure Artifacts feed in Azure DevOps Server 2022.

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. In the left navigation pane, select npm. If this is your first time using Azure Artifacts with npm, make sure you've installed the prerequisites.

  4. Under the Project setup section, select Windows or Other depending on your operating system, then follow the provided instructions to configure your config file and connect to your Azure Artifacts feed.

    A screenshot that shows how to set up an npm project and connect to an Azure Artifacts feed in Azure DevOps Server 2020.

Important

Npm supports only a single registry setting in your npmrc file. To use multiple registries, you must use upstream sources or scopes.

Publish packages to your feed

To successfully run the publish command, you must first authenticate with your feed. If you haven’t done this yet, follow the steps in the Connect to a feed section then continue with the instructions below.

  • In your project directory, run the following command to publish the npm package defined in your package.json:

    npm publish
    

Important

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

Restore packages from your feed

To successfully run the restore command, you must first authenticate with your feed. If you haven’t done this yet, follow the steps in the Connect to a feed section then continue with the instructions below.

  1. In your project directory, run the following command to restore all npm packages:

    npm install
    
  2. To restore a specific npm package, run the following command from your project directory:

    npm install --save <PACKAGE_NAME>