Skip to content

Commit 33a4762

Browse files
Merge pull request #8103 from MicrosoftDocs/artifacts/448715
Npm feed auth
2 parents 8b98fb3 + 9a005cc commit 33a4762

File tree

5 files changed

+68
-95
lines changed

5 files changed

+68
-95
lines changed

docs/artifacts/npm/npm-audit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This synchronization ensures that other projects sharing the same feed will also
3434
npm audit
3535
```
3636

37-
1. If you want to attempt to upgrade to non-vulnerable package versions, make sure you're [connected to your feed](./npmrc.md#connect-to-feed) first, then run the following command in your project directory:
37+
1. If you want to attempt to upgrade to non-vulnerable package versions, make sure you're [connected to your feed](npmrc.md#connect-to-a-feed) first, then run the following command in your project directory:
3838
3939
```Command
4040
npm audit fix

docs/artifacts/npm/npmrc.md

Lines changed: 64 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
---
2-
title: Connect your npm project to Azure Artifacts
3-
description: Learn how to set up your npm project and connect to Azure Artifacts
2+
title: Connect to an Azure Artifacts feed - npm
3+
description: Learn how to set up your npm project and connect to an Azure Artifacts feed.
44
ms.assetid: A5364E3A-3918-4318-AAE0-430EA91AD5F1
55
ms.service: azure-devops-artifacts
66
ms.custom: engagement-fy23
77
ms.topic: conceptual
8-
ms.date: 03/13/2025
8+
ms.date: 07/08/2025
99
monikerRange: '>= azure-devops-2020'
1010
"recommendations": "true"
1111
---
1212

13-
# Connect your npm project to Azure Artifacts
13+
# Connect to an Azure Artifacts feed - npm
1414

1515
[!INCLUDE [version-gt-eq-2020](../../includes/version-gt-eq-2020.md)]
1616

17-
Azure Artifacts enables developers to manage their packages from various sources, including both public registries like npmjs.com and private feeds. To authenticate with Azure Artifacts, you'll need to configure your npm config file. This file contains feed URLs and credentials used by npm, offering options to customize your npm client behavior, such as setting up proxies, defining default package locations, or configuring private package feeds. The *npmrc* file is typically located in the user's home directory but can also be created at the project level to override default settings.
17+
Azure Artifacts enables developers to manage packages from various sources, including public registries like *npmjs.com* and private feeds. To authenticate with Azure Artifacts, you need to configure your *.npmrc* config file. This file stores feed URLs and credentials used by npm, and it allows you to customize client behavior such as setting up proxies, defining default package locations, or configuring access to private feeds. The *.npmrc* file is typically located in the user's home directory, but can also be created at the project level to override default settings.
1818

1919
## Prerequisites
2020

21-
- An Azure DevOps organization. [Create one for free](../../organizations/accounts/create-organization.md).
21+
| **Product** | **Requirements** |
22+
|--------------------|--------------------|
23+
| **Azure DevOps** | - An Azure DevOps [organization](../../organizations/accounts/create-organization.md).<br>- An Azure DevOps [project](../../organizations/projects/create-project.md).<br>- An Azure Artifacts [feed](../get-started-npm.md#create-a-feed)<br> - [Download and install Node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).|
2224

23-
- An Azure DevOps project. Create a new [project](../../organizations/projects/create-project.md#create-a-project) if you don't have one already.
25+
## Connect to a feed
2426

25-
- An Azure Artifacts feed. [Create one for free](../get-started-npm.md#create-a-feed).
27+
Azure Artifacts recommends using two separate *.npmrc* configuration files. One should be stored locally to store your credentials, while the other should be added to your project directory alongside your *package.json* to define your feed URL. This approach allows you to share your project-level configuration without exposing sensitive information.
2628

27-
- [Download and install Node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
29+
To set up the credentials file, create or update the *.npmrc* file and include all necessary registry credentials. This enables the npm client to easily access your credentials for authentication.
2830

29-
## Connect to Feed
30-
31-
Azure Artifacts recommends using two separate configuration files. The first is dedicated to authenticating with Azure Artifacts, while the second should be kept locally to store your credentials. This approach allows you to share your configuration file while keeping your credentials secure.
32-
33-
To set up the second file, place it in your home directory on your development machine and include all your registry credentials. This enables the npm client to easily access your credentials for authentication.
34-
35-
The following steps guide you through setting up the first configuration file. Select the tab that corresponds to your development environment:
31+
The following steps guide you through setting up the project-level configuration file. Select the tab that corresponds to your development environment:
3632

3733
::: moniker range="< azure-devops"
3834

@@ -47,19 +43,31 @@ The following steps guide you through setting up the first configuration file. S
4743

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

50-
1. Select **Artifacts**, and then select **Connect to Feed**.
51-
52-
:::image type="content" source="../media/npm-connect-to-feed-azure-devops.png" alt-text="A screenshot showing how to connect to a feed in Azure DevOps Services.":::
46+
1. Select **Artifacts**, and then select your feed from the dropdown menu.
47+
48+
1. Select **Connect to Feed** and then select **npm** from the left navigation pane.
49+
50+
1. Add a *.npmrc* to your project, in the same directory as your *package.json* and paste the provided snippet from the **Project setup** section into the file.
51+
52+
:::image type="content" source="../media/npm-project-setup-azure-devops.png" alt-text="A screenshot displaying how to set up your npm project and connect to a feed.":::
5353

54-
1. Select **npm** from the left sidebar. If this is the first time using Azure Artifacts with npm, make sure you've installed the prerequisites.
54+
1. Run the following command to get an Azure Artifacts token added to your user-level *.npmrc* file. You don’t need to run this every time—npm will return a **401 Unauthorized** error when it’s time to refresh the token.
55+
56+
```
57+
vsts-npm-auth -config .npmrc
58+
```
59+
60+
### [Other](#tab/other/)
61+
62+
1. Sign in to your Azure DevOps organization, and then navigate to your project.
5563
56-
1. Follow the instructions in the **Project setup** section to connect to your feed.
64+
1. Select **Artifacts**, and then select your feed from the dropdown menu.
5765
58-
:::image type="content" source="../media/npm-project-setup-azure-devops.png" alt-text="A screenshot showing how to set up your npm project.":::
66+
1. Select **Connect to Feed** and then select **npm** from the left navigation pane.
5967
60-
### [Linux/macOS](#tab/Linuxmac/)
68+
1. Add a *.npmrc* file to your project's directory. This should be the same directory where your *package.json* file is located.
6169
62-
1. Add a *.npmrc* file in your project's directory, in the same directory as your *package.json* file, and paste the following snippet into it.
70+
1. Paste the snippet provided in the **Project setup** section into your *.npmrc* file. Your file should look similar to the following:
6371
6472
```
6573
registry=https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/npm/registry/
@@ -99,19 +107,19 @@ The following steps guide you through setting up the first configuration file. S
99107
100108
1. Generate a [personal access token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) with **packaging read and write** scopes.
101109
102-
1. Run the following command in a command prompt window, and then paste your personal access token when prompted. Once done, copy the generated Base 64 encoded value.
110+
1. Run the following command in a command prompt window. When prompted, paste your personal access token (PAT) and press **Enter**. The script will return a Base64-encoded version of your PAT, copy that value to use in the next step.
103111
104112
```
105113
node -e "require('readline') .createInterface({input:process.stdin,output:process.stdout,historySize:0}) .question('PAT> ',p => { b64=Buffer.from(p.trim()).toString('base64');console.log(b64);process.exit(); })"
106114
```
107115
108-
1. If you're on Linux/Mac, you can alternatively use the following command to convert your personal access token to Base 64. Copy the resulting Base64 encoded value.
116+
1. If you're using Linux or macOS, you can run the following command in your terminal to convert your personal access token (PAT) to a Base64-encoded string. Copy the resulting value to use in the next step.
109117
110118
```
111119
echo -n "YOUR_PERSONAL_ACCESS-TOKEN" | base64
112120
```
113121
114-
1. Replace the placeholders *[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]* in your user *.npmrc* file with the encoded personal access token obtained from the previous step.
122+
1. Replace the placeholders *[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]* in your user-level *.npmrc* file with the Base64-encoded personal access token you generated in the previous step.
115123
116124
* * *
117125
@@ -123,23 +131,30 @@ The following steps guide you through setting up the first configuration file. S
123131
124132
1. Sign in to your Azure DevOps collection, and then navigate to your project.
125133
126-
1. Select **Artifacts**, and then select **Connect to Feed**.
134+
1. Select **Artifacts**, select your feed from the dropdown menu, and then select **Connect to Feed**.
127135
128136
:::image type="content" source="../media/server-2022-1-connect-to-feed.png" alt-text="A screenshot showing how to connect to a feed in Azure DevOps Server 2022.1.":::
129137
130-
1. Select **npm** from the left sidebar, and then follow the instructions in the **Project setup** section to set up your config file.
138+
1. Select **npm** from the left, and then follow the steps in the **Project setup** section to configure your .npmrc. file and authenticate with your feed.
131139
132140
:::image type="content" source="../media/npm-project-setup-server-2022-1.png" alt-text="A screenshot showing how to set up your npm project in Azure DevOps Server 2022.1.":::
133141
134-
### [Linux/macOS](#tab/Linuxmac/)
142+
### [Other](#tab/other/)
135143
136-
1. Add a *.npmrc* file in your project's directory, in the same directory as your *package.json* file, and paste the following snippet into it.
144+
1. Sign in to your Azure DevOps collection, and then navigate to your project.
145+
146+
1. Select **Artifacts**, and then select your feed from the dropdown menu.
147+
148+
1. Select **Connect to Feed** and then select **npm** from the left navigation pane.
149+
150+
1. Add a *.npmrc* file in your project's directory, in the same directory as your *package.json* file, and paste the snippet provided in the **Project setup** section into your *.npmrc* file. Your file should look similar to the following:
137151
138152
```
139153
registry=http://<SERVER_NAME>/<COLLECTION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/npm/registry/
140154
141155
always-auth=true
142156
```
157+
143158
### Setup credentials
144159
145160
1. Copy the following snippet and paste it into your user-level *.npmrc* file:
@@ -172,13 +187,13 @@ The following steps guide you through setting up the first configuration file. S
172187
173188
1. Generate a [personal access token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) with **packaging read and write** scopes.
174189
175-
1. Run the following command in a command prompt window, and then paste your personal access token when prompted. Once done, copy the generated Base 64 encoded value.
190+
1. Run the following command in a command prompt window. When prompted, paste your personal access token and press **Enter**. The script will return a Base64-encoded version of your PAT, copy that value to use in the next step.
176191
177192
```
178193
node -e "require('readline') .createInterface({input:process.stdin,output:process.stdout,historySize:0}) .question('PAT> ',p => { b64=Buffer.from(p.trim()).toString('base64');console.log(b64);process.exit(); })"
179194
```
180195
181-
1. Replace the placeholders *[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]* in your user *.npmrc* file with the encoded personal access token obtained from the previous step.
196+
1. Replace the placeholders *[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]* in your user-level *.npmrc* file with the Base64-encoded personal access token you generated in the previous step.
182197
183198
* * *
184199
@@ -194,13 +209,19 @@ The following steps guide you through setting up the first configuration file. S
194209
195210
:::image type="content" source="../media/server-2020-1-connect-to-feed.png" alt-text="A screenshot showing how to connect to a feed in Azure DevOps Server 2020.1.":::
196211
197-
1. Select **npm** from the left, and then follow the instructions in **Project setup** to set up your config file.
212+
1. Select **npm** from the left, and then follow the steps in the **Project setup** section to configure your .npmrc. file and authenticate with your feed.
198213
199214
:::image type="content" source="../media/npm-project-setup-server-2020-1.png" alt-text="A screenshot showing how to set up your npm project in Azure DevOps Server 2020.1.":::
200215
201-
### [Linux/macOS](#tab/Linuxmac/)
216+
### [Other](#tab/other/)
217+
218+
1. Sign in to your Azure DevOps collection, and then navigate to your project.
202219
203-
1. Add a *.npmrc* file in your project's directory, in the same directory as your package.json file, and paste the following snippet into it:
220+
1. Select **Artifacts**, and then select your feed from the dropdown menu.
221+
222+
1. Select **Connect to Feed** and then select **npm** from the left navigation pane.
223+
224+
1. Add a *.npmrc* file in your project's directory, in the same directory as your *package.json* file, and paste the snippet provided in the **Project setup** section into your *.npmrc* file. Your file should look similar to the following:
204225
205226
```
206227
registry=http://<SERVER_NAME>/<COLLECTION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/npm/registry/
@@ -209,7 +230,7 @@ The following steps guide you through setting up the first configuration file. S
209230
```
210231
211232
> [!NOTE]
212-
> For Debian, Ubuntu, and other community or entreprise distributions such as Fedora or Redhat make sure you've installed the prerequisites from the [NodeSource distributions repository](https://github.com/nodesource/distributions).
233+
> For Debian, Ubuntu, and other community or enterprise distributions such as Fedora or Redhat make sure you've installed the prerequisites from the [NodeSource distributions repository](https://github.com/nodesource/distributions).
213234
214235
### Setup credentials
215236
@@ -243,73 +264,25 @@ The following steps guide you through setting up the first configuration file. S
243264
244265
1. Generate a [personal access token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) with **packaging read and write** scopes.
245266
246-
1. Run the following command in a command prompt window, and then paste your personal access token when prompted. Once done, copy the generated Base 64 encoded value.
267+
1. Run the following command in a command prompt window. When prompted, paste your personal access token and press **Enter**. The script will return a Base64-encoded version of your PAT, copy that value to use in the next step.
247268
248269
```
249270
node -e "require('readline') .createInterface({input:process.stdin,output:process.stdout,historySize:0}) .question('PAT> ',p => { b64=Buffer.from(p.trim()).toString('base64');console.log(b64);process.exit(); })"
250271
```
251272
252-
1. Replace the placeholders *[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]* in your user *.npmrc* file with the encoded personal access token obtained from the previous step.
273+
1. Replace the placeholders *[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]* in your user-level *.npmrc* file with the Base64-encoded personal access token you generated in the previous step.
253274
254275
* * *
255276
256277
::: moniker-end
257278
258279
> [!TIP]
259-
> Using multiple registries in .npmrc files is supported with [scopes](..//npm/scopes.md) and [upstream sources](../concepts/upstream-sources.md).
260-
261-
::: moniker range="azure-devops"
262-
263-
## Troubleshoot
264-
265-
#### vsts-npm-auth is not recognized
266-
267-
This error indicates that the npm modules folder hasn't been added to your path. Rerun the Node.js setup and make sure to select the `Add to PATH` option. Alternatively, you can add the npm modules folder to your path by modifying the PATH variable to `%APPDATA%\npm` in Command Prompt or `$env:APPDATA\npm` in PowerShell.
268-
269-
:::image type="content" source="./media/node-setup.png" alt-text="A Screenshot showing how to set up node.js.":::
270-
271-
#### Unable to authenticate
272-
273-
- Error: *code E401 npm ERR! Unable to authenticate*: -> Run the `vsts-npm-auth` command with **-F** flag to reauthenticate:
274-
275-
```
276-
vsts-npm-auth -config .npmrc -F
277-
```
278-
279-
#### Reset vsts-npm-auth
280-
281-
Follow these steps to reset your vsts-npm-auth credentials:
282-
283-
1. Uninstall vsts-npm-auth:
284-
285-
```
286-
npm uninstall -g vsts-npm-auth
287-
```
288-
289-
1. Clear your npm cache:
290-
291-
```
292-
npm cache clean --force
293-
```
294-
295-
1. Delete your *.npmrc* file.
296-
297-
1. Reinstall vsts-npm-auth:
298-
299-
```
300-
npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false
301-
```
302-
303-
#### Unable to publish
304-
305-
If you encounter a 403 error, it may indicate a name conflict. In Azure Artifacts, packages are immutable, meaning that once you publish a package to your feed, its version number is permanently reserved. Even if you delete it, you can't publish a new package with the same version number. To address this issue, update the package version in your *package.json* file, and then try again.
306-
307-
::: moniker-end
280+
> Using multiple registries in *.npmrc* files is supported with [scopes](..//npm/scopes.md) and [upstream sources](../concepts/upstream-sources.md).
308281
309282
## Related content
310283
311-
- [Publish npm packages (CLI)](./publish.md)
284+
- [Publish npm packages (CLI)](publish.md)
312285
313-
- [Publish npm packages (YAML/Classic)](../../pipelines/artifacts/npm.md)
286+
- [Restore npm packages](restore-npm-packages.md)
314287
315-
- [Use packages from npmjs.com](./upstream-sources.md)
288+
- [Publish npm packages with Azure Pipelines (YAML/Classic)](../../pipelines/artifacts/npm.md)

docs/artifacts/npm/publish.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ If this is your first time using Azure Artifacts with npm on your machine, follo
4646
4747
## Publish packages
4848
49-
1. If you haven't authenticated with your feed yet, follow the steps in the [Project setup](npmrc.md#connect-to-feed) to connect to your feed and then proceed with the next step once you're done.
49+
1. If you haven't authenticated with your feed yet, follow the steps in the [Project setup](npmrc.md#connect-to-a-feed) to connect to your feed and then proceed with the next step once you're done.
5050
5151
1. Run the following command in your project directory to publish the npm packages listed in your *package.json*:
5252

docs/artifacts/npm/restore-npm-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ If this is your first time using Azure Artifacts with npm on your machine, follo
4343
4444
## Restore packages
4545
46-
1. If you haven't authenticated with your feed yet, follow the steps in the [Project setup](npmrc.md#connect-to-feed) to connect to your feed and then proceed with the next step once you're done.
46+
1. If you haven't authenticated with your feed yet, follow the steps in the [Project setup](npmrc.md#connect-to-a-feed) to connect to your feed and then proceed with the next step once you're done.
4747
4848
1. Run the following command in your project directory to restore all your npm packages:
4949

docs/artifacts/npm/upstream-sources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ If you checked the upstream sources checkbox during the creation of your feed, n
5454

5555
## Install packages from npmjs
5656

57-
Before you save packages from npmjs, make sure your project is set up to connect to your feed. If you haven't done this yet, follow the provided instructions to [set up your npm project](npmrc.md#connect-to-feed) and connect to your feed. In this example, we'll install the *Axios* library for making HTTP requests:
57+
Before you save packages from npmjs, make sure your project is set up to connect to your feed. If you haven't done this yet, follow the provided instructions to [set up your npm project](npmrc.md#connect-to-a-feed) and connect to your feed. In this example, we'll install the *Axios* library for making HTTP requests:
5858

5959
1. Navigate to npmjs at `https://www.npmjs.com//`.
6060

0 commit comments

Comments
 (0)