CI/CD for Node.js Projects with GitHub Actions

Lint, type-check, test, build and deploy: a pipeline that catches mistakes before your users do.
Opportunist ships through an automated CI/CD pipeline. Once deploys are automatic and checked, releasing becomes a non-event, which is exactly what you want.
Run checks on every pull request
name: CI
on: [pull_request]
jobs:
check:
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 run lint
- run: npx tsc --noEmit
- run: npm test --if-present
- run: npm run buildDeploy on merge to main
A second workflow runs on pushes to main and deploys. Because the same checks already passed on the pull request, main stays deployable.
Secrets
Store deploy tokens and API keys in GitHub repository secrets, scoped to the environment that needs them. Never echo them in logs.
Keep it fast
- Cache dependencies with setup-node's cache option.
- Run independent checks in parallel jobs.
- Cancel outdated runs when a new commit is pushed.
Add a smoke test
After deploying, hit a health endpoint or the home page and fail loudly if it does not return 200. Catching a broken deploy in a minute beats hearing about it from a client.









