actions/setup-node: Versions, Caching & Fixes
setup-node installs the Node version you ask for and can cache your package manager for you.
Prefer setup-node’s built-in caching over a manual actions/cache step - it is simpler and correct by default.
Usage
.github/workflows/ci.yml
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm # or yarn / pnpmNotes
node-version-file: .nvmrcreads the version from your repo.cacheneeds a lockfile present to work.- Version-not-found → check the version exists and the spec is valid.
Related guides
actions/cache: Keys, Restore Keys & Best PracticesReference for actions/cache - how cache keys and restore-keys work, what to cache per ecosystem, and how to a…
GitHub Actions Workflow Template for Node.jsA ready-to-use GitHub Actions workflow for Node.js with caching and best practices - copy, commit, and run fa…
How to Cache Dependencies in GitHub Actions (Every Ecosystem)Cache dependencies in GitHub Actions with actions/cache - correct keys and paths for npm, yarn, pnpm, pip, Ma…