---
title: "Publish to npm with an authentication token"
description: "Publish packages to the npm registry from CircleCI using a long-lived npm authentication token."
platform: "Cloud, Server"
doc_version: "Server"
last_updated: "2026-10-20"
---

> For current CircleCI product defaults, deprecated patterns, and Cloud/Server differences, see [AGENTS.md](https://circleci.com/docs/AGENTS.md).
>
> For the complete documentation index and site structure, see [llms.txt](https://circleci.com/docs/llms.txt).

# Publish to npm with an authentication token

In this how-to guide, you will learn how to configure CircleCI to publish to the npm registry using a long-lived npm authentication token.

## Introduction

Setting up CircleCI to publish packages to the npm registry enables project collaborators to release new package versions in a consistent and predictable way.

## 1\. Get the npm `authToken`

Get the npm `authToken` for the account that you wish to use to publish the package. You can do this by logging in to npm (`npm login`). This will save the `authToken` to the `~/.npmrc` file. Look for the following line:

```shell
//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
```

In this case, the `authToken` is `00000000-0000-0000-0000-000000000000`.

## 2\. Set npm token

Go to your [Project Settings](https://circleci.com/docs/guides/server/security/set-environment-variable/#set-an-environment-variable-in-a-project), and set the `NPM_TOKEN` variable to the obtained `authToken`.

## 3\. Configure CircleCI

Configure CircleCI to add the `authToken` to `~/.npmrc`, run `npm publish` and only for versioned tags:

```yaml
version: 2.1

jobs:
  publish:
    docker:
      - image: <docker-image-name-tag>
    steps:
      - checkout
      - run:
          name: Publish to NPM
          command: |
            npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
            npm publish

workflows:
  tagged-build:
    jobs:
      - publish:
          filters: pipeline.git.tag matches /^v[0-9]+(\.[0-9]+)*$/ # only run the publish job on version tags
```

## 4\. Create a new version

When you want to publish a new version to npm, run `npm version` to create a new version:

```shell
npm version 10.0.1
```

This will update the `package.json` file and create a tagged Git commit. Next, push the commit with tags:

```shell
git push --follow-tags
```

## 5\. Publish

If tests passed, CircleCI will publish the package to npm automatically.