Connect pnpm to Artifactory

JFrog Artifactory Documentation

Products
JFrog Artifactory
Content Type
User Guide

You can use the pnpm CLI as a client to install and publish npm packages. Connect pnpm to Artifactory in one of these ways, based on your repository and environment:

JFrog recommends using a virtual repository as the default registry setting. Virtual repositories provide flexibility to access external sources and local repositories, and reconfigure them as needed. For more information on setting up a virtual npm repository, see Create an npm Repository.

Log In to Unscoped Registries using pnpm login

Set an npm repository in Artifactory as your default registry for pnpm. You can also log in to a specific registry without overriding the default.

To set up and log in to a default npm registry using the pnpm CLI:

  1. Run this command:

    pnpm config set registry https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/

    Where:

    • [JFrogPlatformURL]: The URL of your JFrog service endpoint

    • <REPO_NAME>: The name of the target npm repository in Artifactory

    For example:

    pnpm config set registry https://company.jfrog.io/artifactory/api/npm/npm-virtual/
  2. Run this command:

    pnpm login --auth-type=web

    If you are logging in for the first time, repeat this step after accessing the UI for the first time.

Note

You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.

To log in to a specific registry:

Run this command:

pnpm login --registry=[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/ --auth-type=web

Where:

  • [JFrogPlatformURL]: The URL of your JFrog service endpoint

  • <REPO_NAME>: The name of the target repository

For example:

pnpm login --registry=https://company.jfrog.io/artifactory/api/npm/npm-virtual/

Note

You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.

Log In to Scoped Registries using pnpm login

If you work with scoped packages, you can use the --scope flag to specify the scope.

To log in a scoped npm registry using pnpm:

Run this command:

pnpm login --registry=https://company.jfrog.io/artifactory/api/npm/npm-local/ --scope=@<SCOPE>

Where:

  • [JFrogPlatformURL]: The URL of your JPD

  • <REPO_NAME>: The name of the target scoped npm repository in Artifactory

  • <SCOPE>: The scope or namespace

For example:

pnpm login --registry=https://company.jfrog.io/artifactory/api/npm/npm-local/ --scope=@INTERNAL

If you are logging in for the first time, run the command again after accessing the UI for the first time.

Note

You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.

Edit .npmrc file

If you cannot log in manually or if you are using automated scripts, edit the .npmrc file with authentication snippets. This is called basic authentication. You can use basic authentication for unscoped or scoped acces.

To edit the .npmrc file for basic authentication:

  1. Open the .npmrc file in a text editor. The file location varies by operating system:

    • Linux: ~/.npmrc

    • Mac: USER root folder

    • Windows: %USERPROFILE%/.npmrc

  2. Add one of the following code snippets to the .npmrc file based on whether you are configuring unscoped or scoped access:

    • Unscoped:

      registry=https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:_authToken=<TOKEN>

      Where:

      • [JFrogPlatformURL]: The URL of your JPD

      • <REPO_NAME>: The name of the target registry

      • <TOKEN>: Your JFrog identity token

      For example:

      registry=https://company.jfrog.io/artifactory/api/npm/npm-local/:_authToken=Random_Token
    • Scoped:

      @<SCOPE>:registry=https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:_authToken=<TOKEN>

      Where:

      • <SCOPE>: The scope of the registry

      • [JFrogPlatformURL]: The URL of your JPD

      • <REPO_NAME>: The name of the target registry

      • <TOKEN>: Your JFrog identity token

      For example:

      @INTERNAL:registry=https://company.jfrog.io/artifactory/api/npm/npm-local/:_authToken=Random_Token
  3. Save the changes to the file.

Note

You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.

Next Steps: