Edit

Share via


Use packages from the npm registry

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

Azure Artifacts upstream sources enable developers to consume packages from public registries like npmjs.com. Once upstream sources are enabled in your feed, Azure Artifacts automatically saves a copy of any package installed from an upstream source to your feed. This setup offers the greatest flexibility, allowing you to use a mix of scoped and non-scoped packages, including those from public registries, all within a single feed. This setup also ensures continued access to those packages even if the upstream source becomes temporarily unavailable.

Prerequisites

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

Get the tools

If this is your first time using Azure Artifacts with npm on your machine, follow the steps below to set up your environment:

Make sure you've installed Node.js and npm, then run the following command to install vsts-npm-auth:

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

Create a feed

If you already have an Azure Artifacts feed, skip to the next section. Otherwise, create a new one as follows:

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

  2. Select Artifacts, then select Create Feed.

  3. Enter a Name for your feed, set the Visibility to define who can view your packages, and choose the feed Scope. Be sure to check the Include packages from common public sources box to enable upstream sources and allow consumption of packages from public registries.

  4. Select Create when you're done.

Add npmjs upstream

If you've checked the upstream sources checkbox during the creation of your feed, npmjs will be added automatically to the list of upstream sources in your feed. If not, you can add it manually as follows:

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

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

  3. Select the gear icon button gear icon to open Feed settings.

  4. Select Upstream sources, then select Add Upstream.

  5. Select Public source, then select npmjs (https://registry.npmjs.org/) from the dropdown menu.

  6. Select Add when you're done.

  7. Select Save in the top-right corner to apply your changes.

Connect to a feed

Before you can start saving packages from upstream sources to your feed, you must first set up your project and connect to your feed.

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

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

  3. Select Connect to Feed, then select npm from the left panel.

  4. Follow the steps in the Project setup section to configure your .npmrc file and authenticate with your feed. See set up your npm project for details.

Install packages from npmjs

Now that you've authenticated with your feed, you can start installing packages from public registries such as npmjs.com. When you install a package from an upstream source, Azure Artifacts automatically saves a copy of that package to your feed. In this example, you'll install Mongoose, a MongoDB Object Data Modeling (ODM) library that helps with schema definition, data validation, and object modeling in Node.js applications.

Note

To save packages from upstreams, you must have the Feed and Upstream Reader (Collaborator) role or higher. See Feed roles and permissions for more details.

  1. Go to https://www.npmjs.com.

  2. Search for the Mongoose package, then select it to navigate to its details page.

  3. Copy the install command to your clipboard.

  4. In a command prompt window, navigate to your project directory and run the install command.

    npm i mongoose
    

View saved packages

Now that you've installed a package from the npm registry, you can see how Azure Artifacts automatically saves a copy of that package to your feed. Follow these steps to confirm the package was added to your feed:

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

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

  3. From the Source menu in the top-right corner, select npmjs to filter for packages from the npm registry.

  4. The mongoose package you installed in the previous step should now appear in your feed. Azure Artifacts saved a copy automatically when you ran the install command.

    A screenshot displaying the new Mongoose package that was saved from the public npm registry.