You can use the Yarn client to install and publish npm packages. Artifactory supports multiple versions of Yarn:
Yarn V2+ (Modern)
Configure Yarn V2+ (Modern)
To connect Yarn Modern to Artifactory, you can use yarn commands to programmatically configure Yarn with the required permissions.
To connect Yarn Modern to Artifactory:
Run this command to set Artifactory as your default npm registry:
yarn config set --home npmRegistryServer "https://[JFrogPlatformURL]/api/artifactory/npm/<REPO_NAME>/"Where:
[JFrogPlatformURL]: The URL of your JFrog service<REPO_NAME>: The name of the target repository
For example:
yarn config set --home npmRegistryServer "https://company.jfrog.io/api/artifactory/npm/npm-virtual/"Run this command to configure Yarn to always authenticate with Artifactory:
yarn config set --home 'npmRegistries["https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/"].npmAlwaysAuth' trueWhere:
[JFrogPlatformURL]: The URL of your JFrog service<REPO_NAME>: The name of the target repository
For example:
yarn config set --home 'npmRegistries["https://company.jfrog.io/artifactory/api/npm/npm-virtual/"].npmAlwaysAuth' trueRun this command to set your authentication token for Artifactory:
yarn config set --home 'npmRegistries["https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/"].npmAuthToken' <TOKEN>Where:
[JFrogPlatformURL]: The URL of your JFrog service<REPO_NAME>: The name of the target repository<TOKEN>: Your Artifactory identity token
For example:
yarn config set --home 'npmRegistries["https://company.jfrog.io/artifactory/api/npm/npm-virtual/"].npmAuthToken' Random_TokenPoYzI5MGRYSnZiM2w2SWpvaWRIaGlabWxmWTI5dEluMC5zVzE2ODUOptionally, enable non-secure HTTP interaction by running this command:
yarn config set unsafeHttpWhitelist --home --json '["<HOSTNAME>"]'
Where
<HOSTNAME>is the hostname of your JFrog service, without the protocol. For example:yarn config set unsafeHttpWhitelist --home --json '["company.jfrog.io"]'
Configure Yarn V1 (Classic)
To use Yarn Classic with Artifactory, you need to configure the .npmrc file to connect to Artifactory. You can do this configuration in multiple ways:
Connect Yarn Classic to Artifactory using npm commands
To connect Yarn Classic to Artifactory:
Run the following command to set an Artifactory repository as the default npm registry:
npm config set registry [JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/Where:
[JFrogPlatformURL]: The URL of your JPD<REPO_NAME>: The name of the target repository
For example:
npm config set registry https://company.jfrog.io/artifactory/api/npm/npm-virtual/Run one of the following commands to authenticate to Artifactory, and enter your credentials when prompted:
For unscoped registries:
npm login --auth-type=web echo "always-auth=true" >> ~/.npmrc
For scoped registries:
npm login --auth-type=web --scope=@<SCOPE> echo "always-auth=true" >> ~/.npmrc
Where
<SCOPE>is the repository scope.
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.
Connect Yarn Classic to Artifactory with Manual Configuration
If you can't log in manually or using automated scripts, or if you need to use a specific scope, you can edit your .npmrc file manually.
To manually configure the .npmrc file:
Open the
.npmrcfile in a text editor. The location of the file varies by operating system:Linux:
~/.npmrcMac:
USERroot folderWindows:
%USERPROFILE%/.npmrc
Add one of the following snippets to the
.npmrcfile:For unscoped registries:
registry=https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:_authToken=<TOKEN>Where:
[JFrogPlatformURL]: The URL of your JFrog service<REPO_NAME>: The name of the target repository<TOKEN>: Your Artifactory identity token
For example:
registry=https://company.jfrog.io/artifactory/api/npm/npm-local/:_authToken=Random_TokenPoYzI5MGRYSnZiM2w2SWpvaWRIaGlabWxmWTI5dEluMC5zVzE2ODUFor scoped registries:
@<SCOPE>:registry=https://[JFrogPlatformURL]/artifactory/api/npm/<REPO_NAME>/:_authToken=<TOKEN>Where:
<SCOPE>: The scope of the repository[JFrogPlatformURL]: The URL of your JFrog service<REPO_NAME>: The name of the target repository<TOKEN>: Your Artifactory identity token
For example:
@internal:registry=https://company.jfrog.io/artifactory/api/npm/npm-local/:_authToken=Random_TokenPoYzI5MGRYSnZiM2w2SWpvaWRIaGlabWxmWTI5dEluMC5zVzE2ODU
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: