Sign up for free

or sign up with

Thanks for teaming up with Buddy

Check your inbox and click the verification link to let your code flow.

How to automate tests and deployments of Node.js apps with Buddy

We designed Buddy to help developers gain the upper hand within the ever changing web environment by automating and streamlining development process to the maximum. This guide will tell how to achieve that by introducing Continuous approach to your workflow, so that you'll be able to deliver better Node.js apps more often with as little hassle as possible.

Objectives of this guide

Upon completing this guide you will be able to:

  • Understand the idea of Continuous Integration and Delivery
  • Configure tests for your Node.js app
  • Automate package deliveries upon every change to code

Automating releases with CI/CD

The concept of Continuous Integration and Delivery assumes that your software is always tested and ready to deploy with every release. Buddy supports a wide variety of tools and frameworks that let you achieve that by constructing your own delivery workflow.

Employing Continuous Integration will allow you to:

  • produce reliable software in short iterations
  • receive feedback faster any time a change is made to the system
  • ensure all tests are performed in one consistent environment across all developers
  • facilitate manual QA processes by applying automatic continuous testing on the build server
  • avoid last-minute panic in the office before deployments to production :)
  • automate repeatable activities and focus on actual coding

Ready to begin? Go!

Prepare Git repository

It's not possible to apply Continuous Integration without first putting your files safe and sound under version control. In this example we're going to use a pre-prepared Node.js project, but you can use any JavaScript project of yours if you like. Fire up Buddy and do the following:

  • Create a new project, choose Buddy as the Git provider, use the Import ZIP archive option and paste the link to our Node.js project: http://assets.buddy.works/guides/buddy-nodejs-demo.zip

    Configuring a new project
    Configuring a new project

NOTES:

  • If you're a GitHub user, you can fork the sample project from our profile, select GitHub as the provider, and select the project from the list upon integrating
  • If you're not familiar with Git, this guide will get you started.

Create delivery pipeline

Pipelines let you plan and execute actions that will build and test your app and deploy it to the server. This way you're able to release stable software more frequently which is one of the main goals of Continuous Integration. Let's create a pipeline that will test and deliver your app on every push to branch in the repository:

  • Add a new pipeline, set the trigger mode to On every push and assign it to the branch to which you'll push the changes, so that Buddy knows when to launch the tests.
Adding new pipeline
Adding new pipeline

You can also set the trigger mode to manual or recurrent, which is useful for stage and production servers, or set a wildcard if you like to trigger the release from more than one branch. You can read more about pipelines and their settings here.

Configure tests for your Node.js app

Now we need to configure an action that will run the tests. Buddy uses Docker containers with pre-installed tools (apps, frameworks, etc.) that you can modify to your liking.

  1. Select Docker image with pre-installed Node.js from the action list:

    Adding Node.js action
    Adding Node.js action
  2. Here you can specify the commands that will be run with each execution. The default commands for this action are:

    • npm install - installation of dependencies
    • npm test - running tests
  3. Click Add action when you're ready to save all changes.

    Configuring action settings
    Configuring action settings

NOTES

  • To select the version of Node.js for testing, click the Docker image → Change image. If you want to test your app in different instances, just add more actions with a different Node.js versions
  • You can install additional tools in the Setup Commands field
  • If your tests require a database to run (eg. MongoDB), you can set it up in the Microservices tab
Configuring action settings
Configuring action settings

Automate deployment to server

Once the unit tests are over, you can use Buddy to deploy the app to the server where you can eg. run integration tests or preview it to your client. Automating these activities is the core of the Continuous Delivery approach.

  1. Add another action and select the transfer method for your server type. In this example we'll use SFTP:

    Choosing transfer action
    Choosing transfer action
  2. On the action settings screen, select Git repository as the source so that Buddy will only deploy the tested app without any packages generated by npm. We don't want to deploy the packages at the moment because their shape depends on the system where the npm was executed: that's why we should first upload the files and run npm install on the server afterwards.

  3. Select authorization type and provide login details to your server. If everything's correct, Buddy will add the action to the pipeline:

    Configuring action settings
    Configuring action settings

Run npm install on the server

To ensure everything will work as it should, we now have to run npm install on your server. You can automate the action with an SSH script:

  1. Add another action and select the SSH action

    Choosing SSH action
    Choosing SSH action
  2. Provide authorization details to your server and enter npm install as the command to run:

    Configuring action settings
    Configuring action settings

Run the pipeline

Congratulations! Your pipeline is configured and waiting for execution. Make a push to the selected branch and watch Buddy automatically test and deliver your app:

Running the pipeline
Running the pipeline

Summary

The pipeline described represents a small portion of Buddy's capabilities. You can as well add conditional notifications keeping you aware when a test fails; monitoring actions that will check if your website is up and running; more deployment methods to update assets on IaaS platforms like AWS; or restart your server with an SSH script once the deploy is over.

In general, it all boils down to configuring your pipeline and choosing the right action for the process that you want to optimize. If you're looking for more inspiration how to set up your workflow, have a look at the rest of our guides or drop a line to support@buddy.works with a short description of your development process and we'll tell you how to make it better with Buddy.

Start with a free account if you don’t have an account yet

Join our development automation movement!

Download On-Premises Installation