Travis CI is service for Continuous Integration and it is easy to integrate with the projects on GitHub. It support many programming languages. Travis CI will run unit tests after the project update and report the results. This article will introduce how to integrate node.js projects.

Enable Travis CI for GitHub project

You can sign in with GItHub account and find your projects on GitHub. Go to the Accounts page on the top-right side.
Enable Travis CI for GitHub project
Click the toggle to enable.


Add .travis.yml file to your project root. It describe that how to run the CI flow and environment. It bases on your programming language.

You can find the build lifecycle on the doc. Of course, it will git clone your project and checkout specific version at first.

  • before_install
  • install
  • before_script
  • script
  • after_success or after_failure
  • after_script
  • OPTIONAL before_deploy
  • OPTIONAL deploy
  • OPTIONAL after_deploy

In Node.js language, the install step run following command in default:

npm install

And script step is:

npm test

You can overwrite them. An example of travis.yml in node.js:

language: node_js
- "0.11"
- "0.10"
- "0.8"
before_install: npm install mocha -g

Write Unit Tests

Write unit test and make sure it can run by npm test. Please refer to How to Write a Library for Node.js and Browser with Mocha Unit Tests.


You can add the badge in the to show the build result.

[![Build Status](](

You will see

Build Status

URL format is


Update Project

Now, it will trigger build flow after you update your project. You can check the result by badge or go to Travis CI web site.

Further Reading

How to Write a Library for Node.js and Browser with Mocha Unit Tests
How to Measure JavaScript Code Coverage With jscoverage