Spring Fresh Sale! - Up To 67% OFF BDIX Hosting + Free Domain
Node.js

How to Set Up CI/CD for a Node.js App with GitHub Actions

CI/CD automatically tests your Node.js code on every push and deploys it when tests pass — so you ship faster and catch problems before they reach production. GitHub Actions builds this right into your repository with a single workflow file.

CI vs CD

  • Continuous Integration (CI) — automatically install, build and test your code on every push.
  • Continuous Deployment (CD) — automatically deploy when the tests pass.

A basic CI workflow

Create .github/workflows/ci.yml:

name: CI
on: [push]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 'lts/*' }
      - run: npm ci
      - run: npm test

Now every push runs your tests on a clean machine.

Adding deployment

After tests pass, add a deploy step — commonly connecting to your VPS over SSH to pull the new code and reload the app with PM2, or building and pushing a Docker image. Store credentials as encrypted repository secrets, never in the workflow file.

Good pipeline practices

  • Run linting and tests before deploy, so broken code never ships.
  • Deploy only from your main branch to keep production stable.
  • Keep secrets in encrypted secrets — see managing secrets.
  • Reload with zero downtime via graceful shutdown.

Frequently asked questions

Do I need CI/CD for a small project?

Even small projects benefit from automated tests on every push — it catches mistakes early. Automated deployment is optional but saves time and reduces manual errors once you are deploying regularly.

How do I deploy to my VPS from GitHub Actions?

Add a step that connects over SSH using a key stored as a repository secret, pulls the latest code, installs dependencies, and reloads the app. Keep the private key only in encrypted secrets.

Where do I store passwords and keys?

In GitHub's encrypted repository or environment secrets, referenced in the workflow. Never commit credentials to the repo or place them directly in the workflow file.

Was this article helpful?