ARTIFACTORY : How to configure NPM private registry using NPM PAT

AuthorFullName__c
Ilan Klein
articleNumber
000005948
FirstPublishedDate
2024-01-03T06:53:15Z
lastModifiedDate
2025-05-15

ARTIFACTORY : How to configure NPM private registry using NPM PAT

Configure the NPM private registry using the NPM Personal Access Token(PAT)


Artifactory supports personal access tokens (PAT) for NPM from Artifactory version 7.36.8 and above.

Prerequisites: 

  1. Private npm packages that are published in your npm private registry.
  2. NPM Personal Access Token(PAT).
  3. Users with valid read permissions should have access to the package and the organization and they can create Token.
How to create the NPM Personal Access Token(PAT)
1. Visit https://www.npmjs.com/ click on the profile at the right side of your npm registry page and click on the Access Token option as below.

User-added image

2. Click on Generate Token select any token from the dropdown (Granular or Classic Token) enter the required information over the page and click on Generate Token and a new Token will be created in the format of “npm_abcdxxxxxxxxxx”

User-added image

User-added image

Here you can create the Organisation and include the Token specific to the Organisation by selecting nay organisation from the checkbox while creating the Token.

NOTE: The Token should be created in the npmjs website for the specific user who has read access to the artifact or organization.
 
Configuring Artifactory with npm PAT Token:
1. Set Up an Artifactory Repository
Install JFrog Artifactory: First, ensure you have JFrog Artifactory installed and running. You can follow the installation guide provided by JFrog.

2. In the Artifactory UI, create a new npm Remote Repository and configure the following fields:
  • Username - enter the username of your npmjs.com account.
  • Password / Access Token - enter your npmjs.com Granular Access Token or Classic Token.
  • Enable Token Authentication - check this checkbox.

After filling in the fields, click Test Connection to verify that Artifactory can authenticate to npmjs.com successfully, then save the repository.

Note
Do not leave the username blank or use a dummy value. A valid npmjs.com username and a valid token generated on the npmjs.com website are required.


User-added image 

3. Then configure your npm client to use your Artifactory repository. You can do this using the npm config command:
npm config set registry https://<artifactory-url>/artifactory/api/npm/<npm-repo-name>
Replace <artifactory-url> with the URL of your Artifactory instance and <npm-repo-name> with the name of your npm repository.

If your npm registry requires authentication, you'll need to configure your npm client to use the credentials:
npm login --registry https://<artifactory-url>/artifactory/api/npm/<npm-remote-repo-name>
You'll be prompted to enter your Artifactory credentials.

Kindly follow NPM Private package for a more detailed explanation
 
4. Install the private npm packages using the following,
npm install --registry https://<artifactory-url>/artifactory/api/npm/<npm-remote-repo-name> <package-name>

Replace <package-name> with the name of the private package you want to install.

5. Here are the sample log entries while resolving npm private registry artifacts from our lab environment.
 
==> artifactory-request.log <==
2023-10-17T15:37:53.887Z|41203552e33bab16|0.0.0.0|admin|GET|/api/npm/t-npm-remote/@testorg%2ftestpvtpkg|200|-1|0|645|npm/9.5.0 node/v19.7.0 darwin x64 workspaces/false

==> artifactory-request-out.log <==
2023-10-17T15:37:53.529Z|41203552e33bab16|t-npm-remote|testjfrog|HEAD|https://registry.npmjs.org/@testorg%2Ftestpvtpkg|200|0|0|282
2023-10-17T15:37:53.696Z|41203552e33bab16|t-npm-remote|testjfrog|GET|https://registry.npmjs.org/@testorg%2Ftestpvtpkg|200|0|1467|160

==> artifactory-access.log <==
2023-10-17T15:37:53.705Z [41203552e33bab16] [ACCEPTED DEPLOY] t-npm-remote-cache:.npm/@testorg/testpvtpkg/package.json  for client : admin/X.X.X.X
 
Note: Do not leave the username blank or don't include any dummy username in the field. We need to pass a valid username and token generated on the NPMJS website.