GitHub Actions Workflow Template for Node.js
A complete, caching-enabled GitHub Actions workflow for Node.js. Drop it in .github/workflows/ci.yml and adjust.
This template builds and tests a Node.js project with dependency caching and sensible defaults. It uses setup-node built-in caching.
The workflow
.github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
build:
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 --if-present
- run: npm run build --if-present
- run: npm testWhat it does
- Installs with
npm cifor reproducible builds - Caches the npm store
- Runs lint, build, and tests
Run it cheaper
Change runs-on: ubuntu-latest to a Latchkey label to run this same workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.
Related guides
GitHub Actions Workflow Template for Docker (build & push)A ready-to-use GitHub Actions workflow for Docker (build & push) with caching and best practices - copy, comm…
How to Use Matrix Builds in GitHub ActionsUse GitHub Actions matrix builds to test across versions and OSes in parallel - strategy.matrix, include/excl…
Node.js "JavaScript heap out of memory" in CI - Fix FATAL Heap ErrorsFix "FATAL ERROR: Reached heap limit - JavaScript heap out of memory" in CI builds by raising the V8 heap lim…