﻿# Rotate NPM Tokens with Dotenvx Armor ⛨. Automatically.

 Scott Motte · December 11, 2025

**NPM's new short-lived tokens** strengthen security, but they **make rotation painful.** Every 90 days (or sooner) you have to manually create a fresh token, set it in your CI, and make sure nothing breaks. [1](#footnote1)

![](https://github.com/user-attachments/assets/9868574d-2e81-4654-b4bc-b1c66df19784)

This was a real problem for us. We publish [64 npm packages](https://www.npmjs.com/org/dotenvx), and rotating tokens across all of them by hand was not going to be sustainable. Every expiration meant touching dozens of pipelines and praying the next publish didn't fail.

So we built a solution. Introducing [Dotenvx Rotate](/docs/custody/armor/) - part of Dotenvx Armor ⛨.

## How It Works

Install [dotenvx-armor](/armor/).

```console
$ curl -sfS https://dotenvx.com/armor | sh
```

Run `rotate npm connect` to connect [npm](https://npmjs.com).

```console
$ dotenvx-armor rotate npm connect
```

When prompted enter your npm username and password.

```console
$ dotenvx-armor rotate npm connect
✔ npm username: USERNAME
✔ npm password: PASSWORD
```

This opens a local browser session, connecting your npm account.

![](https://github.com/user-attachments/assets/49ee113b-95dd-4586-87ca-06da3b0f8d20)

> IMPORTANT: Note that this is **local only** - this way we can bypass the need for storing your credentials.

Complete any 2FA steps manually.

![](https://github.com/user-attachments/assets/a7487c65-0ee6-4415-9a94-d1e64a377e66)

On success, return to your CLI, and you will see a passcard created.

```console
$ dotenvx-armor rotate npm connect
✔ npm username: USERNAME
✔ npm password: PASSWORD
✔ connected [https://armor.dotenvx.com/go/pas_1234..]
```

*Dotenvx Passcards* are special connectors allowing account access.

Next, use the passcard to rotate your npm token.

## Rotate

Run `rotate` on the passcard.

```console
$ dotenvx-armor rotate dotenvx://pas_1234..
⠏ rotating..
```

It takes 10-30 seconds. On success, it returns a Dotenvx Rotation Token (ROT).

```console
$ dotenvx-armor rotate dotenvx://pas_1234..
✔ rotated [https://armor.dotenvx.com/go/pas_1234..]
⮕ next run [dotenvx-armor get dotenvx://rot_a2c4..]
```

*Dotenvx Rotation Tokens (ROTs)* are special tokens that can change value. You can think of them as proxy tokens.

Next, let's get the value for it.

## Get

Run `get` on the rotation token.

```console
$ dotenvx-armor get dotenvx://rot_a2c4..
npm_d2cJ..
```

It returns your npm token. Cool!

## Rotate Again

Run `rotate` on the passcard again.

```console
$ dotenvx-armor rotate dotenvx://pas_1234..
✔ rotated [https://armor.dotenvx.com/go/pas_1234..]
⮕ next run [dotenvx-armor get dotenvx://rot_a2c4..]
```

And `get` the ROT again.

```console
$ dotenvx-armor get dotenvx://rot_a2c4..
npm_cbGY..
```

The value changed. Way cool!

That's the ROT at work. ROTs introduce a new key rotation primitive: the npm token rotates, the reference does not. This is useful for operations, especially CI/CD.

## CI/CD

Previously, our CI/CD had `npm publish` with a hardcoded `secrets.NPM_TOKEN`:

```yaml
npm:
  ...
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: '18.x'
        registry-url: 'https://registry.npmjs.org'
    - run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```

### Step 1

We first replaced `secrets.NPM_TOKEN` with `env.NODE_AUTH_TOKEN`.

```yaml
npm:
  ...
  runs-on: ubuntu-latest
  steps:
    ...
    - run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }}
```

### Step 2

Then we added a step to:

- [Install dotenvx-armor](/docs/install/)
- Run `dotenvx-armor get` to echo its value to `NODE_AUTH_TOKEN`

```yaml
npm:
  ...
  runs-on: ubuntu-latest
  steps:
    ...
    - run: |
        curl -sfS https://dotenvx.sh/armor | sh
        echo "NODE_AUTH_TOKEN=$(dotenvx-armor get dotenvx://rot_a2c4 --token '${{ secrets.DOTENVX_ARMOR_TOKEN }}')" >> $GITHUB_ENV
    - run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }}
```

### Step 3

Last, we set `DOTENVX_ARMOR_TOKEN` in [GitHub Actions Secrets](https://github.com/username/project/settings/secrets/actions) (or GitLab CI, CircleCI, or wherever you run your automated npm publishing).

![](https://github.com/user-attachments/assets/db12882b-8b35-40db-a62f-238df32ff3f6)

Tip: Find your `DOTENVX_ARMOR_TOKEN` on your [Dotenvx Settings Page](https://armor.dotenvx.com/settings).

![](https://github.com/user-attachments/assets/df4f6146-5cf9-44a7-9a22-b967d675f3d8)

On your next CI run, it will inject the latest rotated NPM token and successfully publish your npm module(s).

![](https://github.com/user-attachments/assets/7a201f23-c255-4d75-a46e-326ddf22f0d9)

Incredible!

## Conclusion

Publishing now works indefinitely with rotating NPM tokens, powered by a new rotation primitive (ROTs) and passcard connectors.

- *NPM token leaked?* Just rotate it - all your operations still work.
- *Employee left who knew the old token?* Rotate it - all your operations still work.
- *NPM token should be rotated every N days for compliance?* Put it on a schedule - all your operations still work.

This has worked really well for us. If it sounds useful, you can use it too. Sign up for [Dotenvx Armor ⛨](/armor/).

> P.S. If you're running this at enterprise scale with compliance requirements, scheduled rotation, or broader CI/CD concerns, please [get in touch](mailto:scott@dotenvx.com). We'd like to help.

---

1 [Strengthening npm security: Important changes to authentication and token management](https://github.blog/changelog/2025-09-29-strengthening-npm-security-important-changes-to-authentication-and-token-management/)

---

## Subscribe

A newsletter on making .env – from the creator of dotenv

[Subscribe](/newsletter/)

Unsubscribe any time.

 [Back to blog](/blog/) [Subscribe via RSS](/feed.xml)
