Setting Up Nodejs, Mocha, and Chai with Jenkins


  1. Make new Github Repo

We will have Jenkins hook into a github repository to run our buids. It’s a bit simpler if we create the repo first and clone it down to our dev box in the next step. This way we won’t have to set remote and upstream branches in git.

I used ‘mynodeapp’ as the repo for this little project (see

  1. Setup Dev Box

Now to set up our development machine. We need to install nodejs and npm to get our simple project running.

  • Install nodejs & npm
  sudo apt install -y nodejs npm
  • Make a symbolic link for node->nodejs

Various tools try to call “node” rather than “nodejs”. So we will help them out and make a symbolic link (must have sudo privileges).

  sudo ln -s /usr/bin/nodejs /usr/bin/node
  • Create minimal nodejs project with a mocha/chai unit test

We don’t need much here: npm init npm install mocha create ‘test’ folder and ‘test.js’ file see to imitate.

Be sure to adjust the package.json config file to include:

  "scripts": {
    "test": "./node_modules/.bin/mocha --recursive -R xunit test/ > test-reports.xml"
  • Push to Github
  git commit -am "first commit"
  git push
  1. Setup Jenkins Box
    • Install nodejs & npm
  sudo apt install -y nodejs npm
  • Install Java Runtime Environment
  sudo apt install -y default-jre
  • Download and Run Jenkins
  java -jar jenkins.war
  • Configure Jenkins Project
  1. See it work

  2. DRINK!

Written on January 10, 2017