# npm registry

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

Publish and install private npm packages from npm.registry.sh. The package scope is your workspace and each package version is an artifact version in Buddy.

An NPM Package artifact is a private npm registry at `https://npm.registry.sh/`. You publish and install packages with the regular `npm` client, and each package version is an artifact version in Buddy.

## Package naming

The package name has the form `@<workspace>/<artifact>`: the scope is the workspace, and the name without the scope is the artifact identifier. The `my-lib` artifact in the `my-workspace` workspace corresponds to the `@my-workspace/my-lib` package.

The version from `package.json` becomes the artifact version name.

## Artifact creation

The `npm publish` command automatically creates an artifact if the corresponding artifact does not exist in the workspace. Automatically created artifacts have the Workspace scope, **Buddy Auth** access control, and the **Deny** permission level for all pipelines and sandboxes. Pipeline and sandbox permissions are configured on the artifact's Permissions tab. An incorrect package name may also result in the creation of a new artifact.

> **Info**
>
> If you need an artifact in the project scope or with permissions set before the first publish, create it beforehand in the UI or through the REST API. `bdy artifact create` supports only the Bucket and Container Image types.

In the project sidebar, open **Artifacts**, click **New artifact** and select **NPM Package**. The artifact identifier must match the package name without the scope.

![Artifact types in the New artifact menu](https://buddy.works/docs/artifacts/new-artifact-types.png)

Through the [Artifacts API](https://buddy.works/docs/api/artifacts.md), you create it with `"type": "NPM"`.

## Registry authentication

The `npm` client authenticates in the registry with a Buddy user's [personal access token](https://buddy.works/docs/api/getting-started/oauth2/personal-access-token.md). Add two lines to the project's `.npmrc`:

```
@my-workspace:registry=https://npm.registry.sh/
//npm.registry.sh/:_authToken=${NPM_TOKEN}
```

The first line associates the `@my-workspace` scope with the Buddy registry. The second configures the authentication token. The npm client substitutes `${NPM_TOKEN}` with the value of the corresponding environment variable, allowing the `.npmrc` file to be committed to the repository without exposing the token.

> **Warning**
>
> Do not commit a token written directly in `.npmrc`. The token works with the permissions of the user who generated it.

## Package publishing

In `package.json`, set the name with the workspace scope and the version:

```json
{
  "name": "@my-workspace/my-lib",
  "version": "1.0.0"
}
```

Then publish the package:

```bash
npm publish
```

After a successful publish, `npm` prints `+ @my-workspace/my-lib@1.0.0`, and the `1.0.0` version appears in the artifact's **Versions** tab.

![NPM Package artifact versions](https://buddy.works/docs/artifacts/npm-registry-versions.png)

Published package versions cannot be overwritten. Package changes require publication of a new version.

## Install a package

With the same `.npmrc`, you install the package like any other:

```bash
npm install @my-workspace/my-lib
```

`npm view @my-workspace/my-lib versions` returns the list of published versions. An NPM Package artifact has no **Browse** tab, so you check the package content after installation.

## Registry usage in pipelines

In the pipeline, save the token as an encrypted `NPM_TOKEN` variable and add the `.npmrc` from the section above to the repository. A BUILD action with a Node.js image then installs packages from the Buddy registry:

```yaml
- action: Install dependencies
  type: BUILD
  docker_image_name: library/node
  docker_image_tag: "22"
  commands: |-
    npm ci
```

Variables and their scope are described in [Variables](https://buddy.works/docs/pipelines/variables.md).

See also:

- [Permissions and access](https://buddy.works/docs/artifacts/permissions-and-access.md) - project roles and artifact access levels
- [Versions](https://buddy.works/docs/artifacts/versions.md) - version names and run history for a version
- [Container registry](https://buddy.works/docs/artifacts/container-registry.md) - private Docker image registry
- [Personal access tokens](https://buddy.works/docs/api/getting-started/oauth2/personal-access-token.md) - generating a token for `.npmrc`
- [Artifacts API](https://buddy.works/docs/api/artifacts.md) - creating an NPM artifact through the REST API
- [Troubleshooting](https://buddy.works/docs/artifacts/troubleshooting.md#npm) - E404 for an existing package and other registry messages


---
Original source: https://buddy.works/docs/artifacts/npm-registry