Connect the npm CLI to Artifactory

JFrog Artifactory Documentation

Products
JFrog Artifactory
Content Type
User Guide

You can use the npm CLI as a client to install and publish npm packages. Connect the npm CLI 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.

npm login for Unscoped Registries

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

To set up and log in to a default npm registry:

  1. Run this command:

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

    Where:

    • [JFrogPlatformURL]: The URL of your JPD

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

    For example:

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

    npm login --auth-type=web

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:

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

Where:

  • [JFrogPlatformURL]: The URL of your JPD

  • <REPO_NAME>: The name of the target repository

For example:

npm 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.

npm login for Scoped Registries

If you work with scoped packages, you can configure the npm client to connect to a scoped Artifactory repository. This does not override the default unscoped registry.

To log in a scoped npm registry:

Run this command:

npm config set @<SCOPE>:registry [JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/

Where:

  • <SCOPE>: The scope or namespace

  • [JFrogPlatformURL]: The URL of your JPD

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

For example:

npm config set @internal:registry https://company.jfrog.io/artifactory/api/npm/npm-internal-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.

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. The location of the .npmrc file is %userprofile%\.npmrc on Windows, the USER root folder on Mac, and ~/.npmrc on Linux. You can use basic authentication for unscoped or scoped packages.

To use basic authentication for unscoped packages:

Add the following snippet to the .npmrc file:

email = <EMAIL>
always-auth = true
registry=https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/
//[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:_authToken=<TOKEN>

Where:

  • <EMAIL>: The email address you use to authenticate to Artifactory

  • [JFrogPlatformURL]: The URL of your JPD

    Note

    Include the protocol, for example https://, on the registry line. Do not include the protocol on the _authToken line.

  • <REPO_NAME>: The name of the target registry

  • <TOKEN>: Your JFrog identity token

For example:

email = jeffry@frog.com
always-auth = true
registry=https://company.jfrog.io/artifactory/api/npm/npm-virtual/
//company.jfrog.io/artifactory/api/npm/npm-virtual/:_authToken=aK9xL2gH4jF6bN8pS0cV3zW1qR7tY5uIeP3oA2sD4fG6hJ8kL0mZ7xV9bN1cdXNlcm5hbWU6U2FtcGxlRW5jcnlwdGVkUGFzc3dvcmQxMjM0NQ==

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 use basic authentication for scoped packages:

Add the following snippet to the .npmrc file:

@<SCOPE>:registry=[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/
//[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:_authToken=<TOKEN>
//[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:email=<EMAIL>
//[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:always-auth=true

Where:

  • <SCOPE>: The scope of the registry

  • [JFrogPlatformURL]: The URL of your JPD

    Note

    Include the protocol, for example https://, on the registry line. Do not include the protocol on the other lines.

  • <REPO_NAME>: The name of the target registry

  • <TOKEN>: Your JFrog identity token

  • <EMAIL>: The email address you use to authenticate to Artifactory

For example:

@internal:registry=https://company.jfrog.io/artifactory/api/npm/npm-internal-virtual/
//company.jfrog.io/artifactory/api/npm/npm-internal-virtual/:_authToken=aK9xL2gH4jF6bN8pS0cV3zW1qR7tY5uIeP3oA2sD4fG6hJ8kL0mZ7xV9bN1cdXNlcm5hbWU6U2FtcGxlRW5jcnlwdGVkUGFzc3dvcmQxMjM0NQ==
//company.jfrog.io/artifactory/api/npm/npm-internal-virtual/:email=jeffry@frog.com
//company.jfrog.io/artifactory/api/npm/npm-internal-virtual/:always-auth=true

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: