How to publish an NPM Package and automate it

February 10, 2019
by Rahil Shaikh
  • node mysql tutorial

If you have managed an open-source project you already know what steps are involved in releasing a new version of the package or a library.

  1. Changing the package version
  2. Creating tags
  3. Adding Github release
  4. Publishing to npm

Developers hate repeating the same things. Automation is the solution. That’s why we have a great package called semantic-release-cli an npm tool which uses semantic-release to completely automate the package publishing process.

In this tutorial, we will learn how to automate the package publishing process for Node.js modules.

Semantic release CLI as the name suggests follows semantic versioning.  Let’s take a quick look at what semantic versioning is.

Given the version number say (1.0.0) (Major.Minor.Patch).

  • Increment the Major number if you make API-incompatible changes.
  • Increment the Minor number if you add features that are backward compatible.
  • Increment the Patch number if you make backward compatible bug fixes.

You can read more about it here.


The semantic-release-cli works on existing projects. Which means your project must follow a standard node project convention, more importantly, it should have a valid package.json.

Let’s first install the package.

npm i semantic-release-cli -g

Semantic release CLI works with a Continuous Integration software. It also sets up Travis CI for us. If you wish to use any other CI software you can print tokens and use them.

In this tutorial, I’ll be using Travis CI. So before we go any further head over to  and create an account with your GitHub id if you haven’t.

Next, we will run the CLI setup.

semantic-release-cli setup

This will take you through the semantic-release-cli setup. Enter the details as it asks.

semantic release cli

semantic release cli

Once the setup is complete, you will have a Travis configuration file .travis.yml and package.json file looking like this.

language: node_js
    - node_modules
  email: false
  - '7'
  - '6'
  - '4'
  - npm prune
  - npm run semantic-release
    - /^v\d+\.\d+\.\d+$/
  "name": "semantically-released",
  "version": "0.0.0-semantically-released",
  "description": "A demo package to demonstrate semantic-release-cli",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 0",
    "semantic-release": "semantic-release pre && npm publish && semantic-release post"
  "keywords": [
  "author": "Rahil Shaikh",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": ""
  "devDependencies": {
    "semantic-release": "^6.3.2"

I have made a few changes to the package.json. I’ve set the package version to 0.0.0-semantically-released and I’ve set the test in the scripts to exit with 0, since we don’t have any tests for the demo.


To trigger a release we need to commit our code with messages following special conventions.

  • Patch release – fix(pencil): stop graphite breaking when too much pressure applied: This Increments the patch number.
  • Feature Release – feat(pencil): add ‘graphiteWidth’ option: This increments the MINOR number.
  • Breaking Release – perf(pencil): remove graphiteWidth option: This increments the MAJOR number.

So all you now have to do is.

  • git add
  • git commit <message in the above format>

And semantic release CLI will take care of your releases. After Travis has successfully run all the tests and the build is successful you will see your package published on npm as well as a GitHub release.

git release

A github release looks like this


Repeating steps in development can be time-consuming and will lead to reduced productivity. Developers must look to automate repetitive steps in the development process. Semantic Release CLI is an awesome utility one can use to automate the package release process for Node.js applications. Here we learned how we can set it up and use it. Give it a try in one of your projects I’m sure you will love it.


Engineer. Blogger. Thinker. Loves programming and working with emerging tech. We can also talk on Football, Gaming, World Politics, Monetary Systems.

Get notified on our new articles

Subscribe to get the latest on Node.js, Angular, Blockchain and more. We never spam!
First Name:

Leave a Comment