Publish to NPM registry
In this how-to guide, you will learn how to configure CircleCI to publish to the NPM registry.
Setting up CircleCI to publish packages to the npm registry makes it easy for project collaborators to release new package versions in a consistent and predictable way.
1. Obtain the npm authToken
Obtain the npm authToken for the account that you wish to use to publish the package. You can do that by logging in to npm (
npm login). This will save the authToken to the
~/.npmrc file. Look for the following line:
In this case, the authToken is
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
npm publish and only for versioned tags:
version: 2.1 jobs: publish: docker: - image: <docker-image-name-tag> auth: username: mydockerhub-user password: $DOCKERHUB_PASSWORD # context / project UI env-var reference 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]+)*/
4. Create a new version
When you want to publish a new version to npm, run
npm version to create a new version:
npm version 10.0.1
This will update the
package.json file and creates a tagged Git commit. Next, push the commit with tags:
git push --follow-tags
If tests passed, CircleCI will publish the package to npm automatically.
Help make this document better
This guide, as well as the rest of our docs, are open source and available on GitHub. We welcome your contributions.
- Suggest an edit to this page (please read the contributing guide first).
- To report a problem in the documentation, or to submit feedback and comments, please open an issue on GitHub.
- CircleCI is always seeking ways to improve your experience with our platform. If you would like to share feedback, please join our research community.
Our support engineers are available to help with service issues, billing, or account related questions, and can help troubleshoot build configurations. Contact our support engineers by opening a ticket.
You can also visit our support site to find support articles, community forums, and training resources.
CircleCI Documentation by CircleCI is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.