Continuous integration means every push gets built and tested automatically. Continuous delivery means a green build can reach production with one approval. This guide builds a github actions pipeline node.js teams can run from scratch: a workflow file in your repository that installs dependencies, runs tests, builds the app, and ships a Docker image, with no server to set up and no pipeline tool to install.
GitHub Actions runs on GitHub hosted runners, which are fresh virtual machines that start for each job and disappear when it ends. You describe the pipeline in a YAML file under .github/workflows, push it, and GitHub runs it on every push and pull request. The free tier covers small teams easily, and the whole setup is versioned with your code, so the pipeline history lives next to the app history.
GitHub Actions pipeline Node.js setup: the first workflow
Create the file .github/workflows/ci.yml in your repository. This github actions ci cd workflow is the smallest useful version, and you can extend it once it runs green. The workflow below runs on pushes to main and on every pull request, checks out the code, sets up Node 20, installs dependencies from the lock file, and runs the tests:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm test
Push the file and open the Actions tab in the repository. The run appears within seconds, and each step shows its log. The cache option on setup-node stores the npm cache between runs, which cuts minutes from repeated builds. Pin the action versions, such as @v4, because an unpinned action can change behavior without a warning. For a fuller walkthrough of the same tool, read our guide to building a CI/CD pipeline with GitHub Actions, which covers the same workflow shape with more deploy options.
Add linting, tests, and a build step
A pipeline that only runs tests misses the failures that linting and the build catch. Add a lint step after install, and a build step after the tests, so a pull request cannot merge with a broken build:
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
Run the same commands on your machine before you push, because a pipeline that fails on a step your laptop never runs will fail often. Keep the test suite fast. A suite that takes twenty minutes will teach the team to skip the pipeline, while a suite that takes two minutes becomes a habit. Split slow integration tests into a separate job that runs on main only, and keep the pull request job to unit tests and the build. If the app ships as a container, the Dockerfile practices in our guide to multi-stage Dockerfiles that shrink images keep the build step small and fast.
Build and push a Docker image from the workflow
The next job builds the image and pushes it to the GitHub Container Registry. It needs a login step and the official build-push action, and it should only run on pushes to main, not on every pull request:
docker:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest
The github actions docker build push job waits for the test job to pass, so a failing test never produces an image. The needs keyword is what enforces that order. The GITHUB_TOKEN is created by GitHub for each run, so no secret has to be stored for registry login. Tag the image with the commit SHA as well as latest, because latest moves and a SHA lets you roll back to an exact build. Our comparison of the best container registries, Docker Hub vs GHCR vs ECR covers where to store the image if GHCR does not fit your setup.
Deploy to a VPS from the pipeline
The last step is the deploy. A github actions deploy vps step uses an SSH key stored as a repository secret, and the simple pattern is to SSH from the runner to your VPS and pull the new image. Store the SSH key as a repository secret, never in the workflow file, and use the official SSH action or a short script step. The remote command pulls the image, stops the old container, and starts the new one:
docker pull ghcr.io/my-org/my-app:latest docker stop my-app || true docker rm my-app || true docker run -d --name my-app -p 3000:3000 --env-file /opt/my-app/.env ghcr.io/my-org/my-app:latest
Keep the deploy step manual for production at first. Add a workflow_dispatch trigger so you can run the deploy by hand after you review the build, and only automate it fully once the pipeline has proven itself for a few weeks. The security checklist in hardening a CI/CD pipeline covers secret handling, least-privilege tokens, and pinning actions, all of which matter more once the pipeline can touch a live server.
Protect main with branch rules and status checks
A pipeline only helps if nobody can skip it. Turn on branch protection for main and require the test job to pass before a merge. Require at least one review on pull requests, and require the branch to be up to date before merging, so a green check on an old commit cannot merge into a changed main. These settings live in the repository settings under Branches, and they take five minutes to set.
Then watch the pipeline for a month and tune it. A job that fails for flaky reasons teaches the team to ignore red builds, so fix flaky tests at once instead of rerunning them. A pipeline that takes too long gets bypassed, so cache aggressively and split slow jobs. Compare the tooling landscape in our guide to the best CI/CD tools in 2026, Jenkins vs GitHub Actions vs GitLab when the team outgrows a single workflow, and keep the habit that matters most: every change goes through the pipeline, and main stays green.