Continuous Integration for Node.js full stack project | Node.js github actions

A Step-by-Step Guide to Continuous Integration for Your Node.js full stack Application

What is Continuous Integration?

The "CI" in CI/CD always refers to continuous integration, an automation process for developers that facilitates more frequent merging of code changes back to a shared branch, or “trunk.” As these updates are made, automated testing steps are triggered to ensure the reliability of merged code changes.

Successful CI means that once a developer’s changes to an application are merged, those changes are validated by automatically building the application and running different levels of automated testing, typically unit and integration tests, to ensure the changes haven’t broken the app. This means testing everything from classes and function to the different modules that comprise the entire app. If automated testing discovers a conflict between new and existing code, CI makes it easier to fix those bugs quickly and often.

How to configure node.js CI?

Imagine that you have a full stack app and its contain two directory one is frontend and second is backend you can see one of my project Click. Now you want to set up continuous integration to build and test both.

Create an .github/workflows directory and inside that create a build.yml file or you can chose your name acording to your requirement and paste the following code

name: Node.js CI
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build-backend:
    runs-on: ubuntu-latest
    strategy:
      matrix:
       node: [20.x]
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/checkout@v4
        with:
          node-version: ${{matrix.node}}
          cache: 'npm'
          cache-dependency-path: 'backend/package-lock.json'

      - name: Install dependencies
        run: npm install
        working-directory: ./backend

  build-frontend:
    runs-on: ubuntu-latest
    strategy:
      matrix:
       node: [20.x]
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/checkout@v4
        with:
          node-version: ${{matrix.node}}
          cache: 'npm'
          cache-dependency-path: 'frontend/package-lock.json'

      - name: Install dependencies
        run: npm install
        working-directory: ./frontend

Github Actions Essential

You can check my first blog Post in order to better understand about github actions.

Did you find this article valuable?

Support Shivam Sharma by becoming a sponsor. Any amount is appreciated!