Deploy to npm registry
In this how-to guide, you will learn how to configure CircleCI to publish to the npm registry.
Introduction
Setting up CircleCI to publish packages to the npm registry enabling 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:
//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, 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:
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:
tags:
only: /v[0-9]+(\.[0-9]+)*/