actions/setup-node
Install a specific Node.js version and cache your npm, yarn, or pnpm dependencies.
What it does
actions/setup-node installs a chosen Node.js version and puts it on PATH. Its cache input is the simplest way to cache dependency downloads without a separate actions/cache step.
Set node-version explicitly (or read it from a file) so builds are reproducible instead of tracking whatever the runner image ships.
Usage
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm' # requires a committed package-lock.json
- run: npm ciInputs
| Input | Description | Default | Required |
|---|---|---|---|
node-version | Version spec, e.g. 20, 20.x, or lts/*. | - | No |
node-version-file | Read the version from a file such as .nvmrc or package.json. | - | No |
cache | Package manager to cache: npm, yarn, or pnpm. | - | No |
cache-dependency-path | Path(s) to the lockfile used for the cache key. | auto | No |
registry-url | Registry to configure for publishing. | - | No |
check-latest | Always resolve the latest matching version. | false | No |
Outputs
| Output | Description |
|---|---|
node-version | The version that was installed. |
cache-hit | true if an exact dependency cache was restored. |
Notes
The cache input needs a lockfile to compute the cache key. Commit package-lock.json, yarn.lock, or pnpm-lock.yaml.
For pnpm, run pnpm/action-setup before setup-node so the pnpm binary exists when the cache is restored.
Common errors
Error: Dependencies lock file is not foundmeanscacheis set but no lockfile was found. Commit a lockfile or pointcache-dependency-pathat it.- A version like
node-version: 20.11that is not on the runner triggers a download; use a broad spec like20orlts/*to avoid brittle pins.
Security and pinning
- Pin setup-node to a commit SHA. Tags like
v4are mutable. - When using
registry-urlto publish, pass the token viaNODE_AUTH_TOKENfrom a secret, never inline.
Frequently asked questions
Do I still need actions/cache with setup-node?
cache input covers dependency caching for npm, yarn, and pnpm. Use actions/cache only for extra paths like build output.How do I cache pnpm?
cache: pnpm on setup-node so the pnpm store is cached.