In this article, I will share with you the concept of CI/CD and apply it to a practical scenario.

What is CI/CD and why should I use CI/CD

CI/CD stands for continuous integration and continuous delivery.

  • Continuous Integration is the process in which all code changes from multiple developers are automatically merged into a single shared repository. Then each integration is verified by an automated tool that checks for code style and runs tests before each build.

  • Continuous Delivery expands upon Continuous Integration by deploying all code changes to a testing environment and/or production environment after the build stage. In order words, all-new features, bug fixes, … will be delivered to the hand of testers/users frequently.

→ This practice of CI/CD significantly reduces the cost of manual operation for developers, hence improve productivity and shorten deployment time.

Practical scenario:

  • A group of developers working on a NodeJS project

  • All code changes from developers are pushed to a Bitbucket repository

  • With each commit pushed to the repository, CircleCI will be triggered. It will check out the latest code, install dependencies and run tests

  • After all, tests are passed, CircleCI deploy code to a remote server via SSH

Why choose CircleCI over Jenkins (and other alternatives)

Besides many other CI/CD tools, in this article, I only compare CircleCI to Jenkins — the most popular CI/CD tool of all time.

First of all, and probably the most distinct difference between Jenkins and CircleCI is that you need a server to host Jenkins there, which requires administration knowledge and a considerable amount of time for configuration/customization. Meanwhile, CircleCI is a cloud-native platform, which means you do not need to set up any server, it just runs out of the box.

Secondly, Jenkins interface is rather old and unintuitive, whereas CircleCI’s design is very friendly. When it comes to configuration, with CircleCI, the yml syntax is clear and easy for developers to read.

In conclusion, CircleCI is a lightweight CI/CD platform that supports almost every programming language out of the box. Developers can also deploy to AWS, Azure, Google Cloud, Heroku, and many other clouds hosting services.

Demo

Prerequisites:

  • Node.js project stored in a Bitbucket repo

  • CircleCI account

  • Remote server that you can connect via SSH. On this server, you must install git, Node.js, and pm2 (recommended tool to manage Node.js processes)

  • Basic knowledge of SSH

Demo setup CI/CD with CircleCI

Setup

1. Configure CircleCI to track commits on Bitbucket repo

  • Create a folder named .circleci at the root of your project, add config.yml file to this folder with the following content:

For a more detailed specification of how to configure CircleCI, please refer to this document.

  • Add your Bitbucket repo to the CircleCI project

→ Now, CircleCI is able to perform the build job specified in the config.yml file.

2. Configure the remote server so that CircleCI can perform the deploy job

Generate an SSH key pair which we will be using throughout this tutorial by executing this command on the terminal:

ssh-keygen -t rsa -C “[email protected]

You will be asked a few questions, remember to let the passphrase empty (at the time when I wrote this article, CircleCI requires an empty passphrase).

→ The results are 2 files: id_rsa (private key) and id_rsa.pub (public key)

  • In Bitbucket repo settings, check if CircleCI Deploy Key has been automatically added, then copy id_rsa.pub and add another key there

In Bitbucket repo settings, check if CircleCI Deploy Key has been automatically added, then copy id_rsa.pub and add another key there

  • In the CircleCI project setting, copy id_rsa and add your private key there

In CircleCI project setting, copy id_rsa and add your private key there

  • In your remote server, append your public key to authorized_keys in ~/.ssh by executing this command:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  • In your remote server, copy your private key into ~/.ssh folder and modify ~/.ssh/config file to include:

Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
  • Add your private key to the ssh-agent by executing this command:

eval "$(ssh-agent -s)"
ssh-add -K ~/.ssh/id_rsa

→ Now every time you push code to Bitbucket, CircleCI will pull code from there and perform a build job on their cloud. After that, it performs a deploy job by connecting to the remote server via SSH, then automatically runs the deploy command on the remote server to pull code from bitbucket, then pm2 to start/restart the process as specified in the config.yml file.

ssh -p your_port_number your_user@your_host 
"cd .. /path/to/your/project; 
git pull;
pm2 start hello_sts";

You are done!

Good job! You have successfully automated the development and deployment processes with CircleCI. Now, without the need to perform manual tasks, your team can work effortlessly to deliver the product in a timely fashion.

This basic tutorial aimed to give you some fundamental knowledge of CircleCI to kick-start you on the DevOps journey. To master the power of CircleCI, dive right into its documentation. The capabilities are endless with so many features waiting for you to explore:

  • First-class Docker support.

  • Workflows for job orchestration.

  • Debug with SSH. Caching.

  • Gain insights about your repository with a visual dashboard.

  • Deploy your application to AWS, Azure, Google Cloud, Heroku, …/

Source: https://medium.com/@blueish/how-to-setup-ci-cd-with-circleci-and-deploy-your-nodejs-project-to-a-remote-server-275a31d1f6c4

Content manager
Thanh (Bruce) Pham
CEO of Saigon Technology
A Member of Forbes Technology Council

Related articles

17 Mobile App Development Trends for 2025
Methodology

17 Mobile App Development Trends for 2025

The mobile app development industry continues to push boundaries, driven by innovations that redefine how users interact with applications. Staying informed about the latest mobile app development trends is essential for developers and businesses to remain competitive and deliver superior user experiences. This article uncovers 17 transformative mobile app trends poised to dominate in 2025. […]
Mobile App Development Process: A Ultimate Guide for Success
Methodology

Mobile App Development Process: A Ultimate Guide for Success

Mobile app development process involves multiple stages. Check the 7 stages here to make sure you have a successful project!
The Ultimate Guide to Fitness App Development
Methodology

The Ultimate Guide to Fitness App Development

Discover everything you need to know about fitness app development: best practices, costs, and more. Start building your own fitness app!
How Much Does It Cost To Make An App in 2025? An Ultimate Guide
Methodology

How Much Does It Cost To Make An App in 2025? An Ultimate Guide

Explore the key factors that impact mobile app development cost and learn strategies to optimize your app development budget.
eCommerce App Development: Everything You Need to Know to Build a Successful App
Methodology

eCommerce App Development: Everything You Need to Know to Build a Successful App

This article offers a thorough guide to eCommerce app development. Let's explore the costs, essential features, and detailed processes!
Popular Cross-platform App Development Frameworks in 2025
Methodology

Popular Cross-platform App Development Frameworks in 2025

Discover the best cross-platform app development frameworks! Compare top choices and their features to find the perfect fit. Check it now!
Native App Development: Everything You Need to Know
Methodology

Native App Development: Everything You Need to Know

Explore this complete guide to native app development and learn how it delivers outstanding performance and seamless user experiences!
Offshore Outsourcing: Benefits, Challenges, and Strategic Approaches
Methodology

Offshore Outsourcing: Benefits, Challenges, and Strategic Approaches

Offshore outsourcing helps businesses cut costs, improve operations, and access global talent. This article explores the benefits of offshore outsourcing.
Custom App Development: Scalable Solutions for Business Growth
Methodology

Custom App Development: Scalable Solutions for Business Growth

Custom app development creates tailored apps with strong architecture, functionality, API integrations, and UI/UX design to meet unique needs.

Want to stay updated on industry trends for your project?

We're here to support you. Reach out to us now.
Contact Message Box
Back2Top