Deploying a NodeJS App from GitHub to Modulus

Written by: Florian Motlik

https://fast.wistia.com/embed/medias/65gro5tump.jsonphttps://fast.wistia.com/assets/external/E-v1.js

How to set up Continuous Integration and Continuous Deployment for a Node.js Application from GitHub to Modulus

In this blog post we're going to deploy a Node.js application from a GitHub repository to Modulus using Codeship.

We've set up a simple Node.js application called codefish which contains some Jasmine specs. We'll use screenshots of this application in this blog post. If you haven't got your own project to set up but you want to follow along on your computer, just fork the repository.

Together, we're going to deploy this application to Modulus using Codeship.

First, sign in to Codeship with GitHub. Codeship needs access to your GitHub repositories to be able to set them up. Let's allow access.

We're back at Codeship. Now let's create your first project.

The first step of your project setup is to select GitHub as your repository provider.

In the list of your GitHub repositories

search for the repository you want to set up and select it. In my case I search for "codefish".

Now your repository is connected and you can set up your test commands:

Codefish is a Node.js application. Therefore let's choose "Node.js" as your technology. This prepopulates the setup commands and the test commands for you.

Codeship suggests Node.js 0.10.25, but you can use whatever Node version you like. To find out the Node version of your project, type node -v in the Terminal.

Just copy your Node version into the nvm install and nvm use statements.

If you want to run Jasmine specs, please install jasmine-node globally additionally to your node modules. In this case just add npm install -g jasmine-node after npm install.

You don't need npm test for your Jasmine specs, so you can comment it out by adding a hash key before the command. Instead, add jasmine-node spec to the test commands to run your Jasmine specs.

Now let's finish your setup and go to the dashboard.

You can trigger a build for your application by pushing to your repository. Let's add the the Codeship status image to the README file. I use markdown syntax to insert the image.

Now commit and push this change.

This triggered a new build on Codeship.

You can access the build details by clicking the arrow on the right. Here you can follow the running build.

A few seconds later your build succeeded! Great!

You see all the commands that were run. After a few initial preparation commands Codeship ran the commands that you specified a few moments ago.

You can inspect the output of a single command by clicking on it. For the codefish application, we can see that two Jasmine specs were run.

You've already pushed to your repository, watched your build log and got a green build. So you can finish the assistant at the top.

Now let's deploy your application to Modulus. Go to your project settings by clicking on the settings icon in the projects dropdown.

Then navigate to the "Deployment" section.

As we want to deploy to Modulus we click on the "Modulus" button.

Next you need to fill in your Modulus API token and project name. To generate an API token install the Modulus command line tool first.

Sign in to Modulus with your Github credentials or the credentials you've used to sign up on Modulus.

Now you can generate an API token

and insert it into your deployment configuration.

In the last config step add the name of your Modulus application. If that application doesn't exist already it will be created.

Now save your deployment by clicking on the green checkmark on the right.

From now on Codeship will deploy your application to Modulus everytime you push to your GitHub repository.

You still need to tell Modulus how to run your application.

In your package.json add "main": "start.js", because this file will start your application's server.

Now commit and push this change

And immediately another build will start running on Codeship. Let's go back to your project overview.

After the commands we already know from your first build, your application also gets deployed to Modulus now.

And about 2 minutes later your application is online.

In the deployment log you can look up your application's URL.

When you open the URL of your Modulus app now, your deployed application appears. You can find mine on codefish-11988.onmodulus.net.

If you need help with setting up your own application, please use the support link in the top-right corner or please tweet us @codeship!

Stay up to date

We'll never share your email address and you can opt out at any time, we promise.