ARTIFACTORY: Publishing NPM Packages to a Subfolder in Artifactory

ARTIFACTORY: Publishing NPM Packages to a Subfolder in Artifactory

Content Type
REST_API
AuthorFullName__c
Jeremy Leopold
articleNumber
000006391
ft:sourceType
Salesforce
FirstPublishedDate
2025-04-01T09:38:38Z
lastModifiedDate
2025-03-31
VersionNumber
2
Overview

The npm client does not support specifying directories for publishing when using npm publish. By default, npm packages are published at the root of the repository. However, it is possible to structure packages within subfolders by manually deploying them to the desired path using the Deploy Artifact REST API or JFrog CLI.
This article outlines how to achieve this while maintaining compatibility with npm install.

Repository Path Structure

Let's say we have a package named test with version 1.0.0. If it is not a scoped package, running npm publish will store it in the repository at the path test/-/test-1.0.0.tgz.

If the package is scoped under @my-scope, publishing it with npm publish would result in the path @my-scope/test/-/@my-scope/test-1.0.0.tgz.

To place the packages under a folder called project, you would deploy them (using the Curl or JFrog CLI clients) to the following paths:

- Non-scoped: project/test/-/test-1.0.0.tgz
- Scoped: project/@my-scope/test/-/@my-scope/test-1.0.0.tgz

Publishing NPM Packages to a Subfolder

To illustrate, we’ll first run npm pack to create the tarball and then publish it to Artifactory using the Deploy Artifact REST API. The following command deploys test-1.0.0.tgz to the npm virtual repository jeremyl-npm under the project directory:
curl -u admin:password -X PUT "http://<JFROG_HOST>/artifactory/jeremyl-npm/project/test/-/test-1.0.0.tgz" -T test-1.0.0.tgz
User-added image 

Retrieving NPM Packages from a Subfolder

We simply install the package with the command npm install test:
 User-added image 

Recommendations

It's important to highlight that we generally recommend using the Set Me Up instructions to integrate clients for each package type, ensuring proper metadata indexing and seamless retrieval. Additionally, rather than using subfolders, you may find it easier to segregate your projects into separate repositories or take advantage of our Projects feature for easier permissions management. Please see our documentation for more information.