Usage
Available Subcommands
| Subcommand | Description |
|---|---|
| npm | Configure npm client for Harness registry |
Currently, only npm configuration is supported. Support for other package managers (Maven, Docker, etc.) is coming soon.
NPM Configuration
Configure npm to use a Harness Artifact Registry virtual npm registry.Usage
Options
Registry identifier (the Harness registry name)
Package registry base URL (e.g.,
https://pkg.harness.io)NPM scope (e.g.,
@myorg). If not provided, configures default registry.Auth token. If not provided, uses token from
hc login.Configure globally for the user (
~/.npmrc)Configure at project level (
.npmrc in current directory)If neither
--global nor --project-level is specified, defaults to --project-level.Examples
Project-Level Configuration
Configure npm for the current project:.npmrc in the current directory.
Global Configuration
Configure npm globally for your user:~/.npmrc.
Scoped Configuration
Configure npm for a specific scope:@mycompany packages to use Harness registry.
Custom Token
Provide a specific auth token:Configuration Output
Successful configuration:Generated Configuration
Project-Level .npmrc
The command creates/updates .npmrc in your project:
Global ~/.npmrc
When using --global, the configuration is written to your home directory:
Using the Configured Registry
After configuration, use npm normally:Install Packages
Publish Packages
View Configuration
Scope-Specific Configuration
Configure different registries for different scopes:.npmrc:
Authentication
Using Login Token
The simplest method is to use the token fromhc login:
Using Custom Token
Provide a specific API token:Environment Variable
Project Setup Workflow
-
Login to Harness:
-
Navigate to your project:
-
Verify package.json exists:
-
Configure npm:
-
Install dependencies:
Validation
The command validates:- ✓ Registry identifier is provided
- ✓ Package URL is provided
- ✓ Account ID is configured (from login)
- ✓ Auth token is available
- ✓
package.jsonexists (for project-level config) - ✓ Cannot use both
--globaland--project-level
Error Messages
Registry Not Specified
--registry flag with your registry identifier.
Package URL Not Specified
--pkg-url flag with the package registry URL.
Not Logged In
hc login to authenticate.
No Auth Token
hc login or provide --token.
Missing package.json
- Run from a directory with
package.json, or - Use
--globalflag instead
Cannot Use Both Flags
Configuration Updates
The command intelligently updates existing.npmrc files:
- Preserves existing configuration
- Updates registry URL if changed
- Updates auth token if changed
- Adds new entries if not present
- Removes empty lines
Security Best Practices
- Use project-level config: Keeps tokens in project directory
- Add .npmrc to .gitignore: Don’t commit auth tokens
- Use environment variables: For CI/CD pipelines
- Rotate tokens regularly: Update tokens periodically
.gitignore Entry
CI/CD Configuration
Verification
Verify the configuration works:Troubleshooting
Installation Fails
Wrong Registry Used
Related Commands
- hc registry list - List available registries
- hc registry get - Get registry details
- hc login - Authenticate with Harness