Harness Artifact Registry provides full support for npm packages, allowing you to host private JavaScript and TypeScript packages.
Overview
NPM registry features:
- Standard npm registry protocol
- Automatic metadata extraction from
package.json
- Scoped package support (
@org/package)
- Version management and dist-tags
- Seamless integration with npm, yarn, and pnpm
Pushing npm packages
Use the hc artifact push npm command to publish packages:
hc artifact push npm <registry-name> <npm-tgz-path> \
--pkg-url <pkg-url>
How it works
The CLI automatically:
- Validates the
.tgz tarball format
- Extracts
package.json from the tarball
- Reads package name and version from
package.json
- Builds the npm upload payload
- Uploads the package to the registry
Create package tarball
Build your npm package:# In your package directory
npm pack
# Creates: your-package-1.0.0.tgz
Upload to registry
Push the tarball:hc artifact push npm my-npm-registry ./your-package-1.0.0.tgz \
--pkg-url https://app.harness.io/registry/pkg
Configure npm client
Set up npm to use your registry:hc registry configure npm my-npm-registry
Installing npm packages
After configuring your npm client, install packages as usual:
# Install from your private registry
npm install your-package
# Or with yarn
yarn add your-package
# Or with pnpm
pnpm add your-package
Registry configuration
Configure npm to use your Harness registry:
Project-level configuration
Create .npmrc in your project:
registry=https://<registry-url>/
//registry-url/:_authToken=<your-harness-token>
Scoped packages
For scoped packages (@myorg/package):
@myorg:registry=https://<registry-url>/
//registry-url/:_authToken=<your-harness-token>
Using the CLI
Automate configuration with:
hc registry configure npm my-npm-registry \
--scope @myorg \
--project
Examples
# Pack and push a public package
npm pack
hc artifact push npm my-registry ./mypackage-1.0.0.tgz \
--pkg-url https://app.harness.io/registry/pkg
Package.json requirements
The package.json must contain both name and version fields
Minimal package.json:
{
"name": "mypackage",
"version": "1.0.0",
"description": "My awesome package",
"main": "index.js"
}
For scoped packages:
{
"name": "@myorg/mypackage",
"version": "1.0.0"
}
CI/CD integration
- name: Publish to Harness
env:
HARNESS_API_KEY: ${{ secrets.HARNESS_API_KEY }}
run: |
npm pack
hc artifact push npm my-registry ./*.tgz \
--pkg-url https://app.harness.io/registry/pkg
publish:
script:
- npm pack
- hc artifact push npm my-registry ./*.tgz --pkg-url $PKG_URL
variables:
HARNESS_API_KEY: $HARNESS_TOKEN
Troubleshooting
package.json must contain 'name' and 'version'
Ensure your tarball was created correctly:# Check tarball contents
tar -tzf mypackage-1.0.0.tgz | grep package.json
# Verify package.json has name and version
npm pack --dry-run
Failed to extract package.json from tarball
Upload failed with 4xx error
Check authentication and permissions:hc auth status
hc registry list # Verify registry exists
See also