npm-quickstart
Last updated on
Prerequisites
- Ensure you have the NPM CLI (
npm) installed on your local machine. - Access to a Harness account with appropriate permissions to create registries and connectors.
Create a NPM Artifact Registry
- Interactive Guide
- Step-by-Step
- Navigate to the Artifact Registry module in your Harness project.
- Click on New Artifact Registry.
- In the Registry Type dropdown, select NPM Registry.
- Provide a Registry Name.
registry name criteria
Your registry name must start with a letter and can include lowercase alphanumerics, _, . and -.
- Optionally, add a Description and Labels for better organization.
- Choose visibility between Public and Private.
- Click Create Registry to finalize.
private registry
This registry will serve as your private NPM registry within Harness.
Configure an Upstream Proxy (Optional)
An upstream proxy allows your registry to fetch NPM packages from external sources if they are not available locally.
- Interactive Guides
- Step-by-Step
Create an upstream proxy
Configure the upstream proxy in your registry
Create an upstream proxy
- In the Artifact Registry module, click the dropdown next to New Artifact Registry and select Upstream Proxy.
- Choose NPM Registry as the proxy type.
- Click Create Proxy to establish the connection.
Configure the upstream proxy in your registry
- In the Artifact Registry module, select an existing Artifact Registry.
- Select the Configuration tab.
- Under Advanced (Optional), select Configure Upstream.
- Select from the list of compatible proxies to add them to your registry.
- Click Save to save the configuration.
upstream proxy caching
If a NPM package isn’t found in your Harness registry, the upstream proxy fetches it from an external registry like NPM Central, reducing duplication and improving resolution.
Publish & Install NPM Packages
Authenticate the CLI with the Harness Registry
- In your Harness NPM Artifact Registry, click Setup Client.
- Create or update your
~/.npmrcfile with the following content:
registry=https://pkg.harness.io/pkg/<account-id>/npm-registry/npm/
//pkg.harness.io/pkg/<account-id>/npm-registry/npm/:_authToken=<TOKEN>
- Click Generate Identity Token to generate a new token that serves as the password for uploading and downloading artifacts.
Publish a Package to the Registry
- Build and publish your package:
npm run build
npm publish
Install your package
- Install your package using npm:
npm install <ARTIFACT_NAME>@<VERSION>
usage
These commands upload or retrieve NPM packages between your local project and the Harness registry.