actions/setup-node: Install Node.js in CI
setup-node installs a specific Node.js version and can cache your package manager for you.
Pin the Node version your project expects and let setup-node handle dependency caching. It supports npm, yarn, and pnpm caching out of the box.
Key inputs (with:)
- node-version: e.g. 20 or 20.11.1.
- node-version-file: read the version from .nvmrc or package.json.
- cache: npm, yarn, or pnpm to cache the dependency store.
- cache-dependency-path: lockfile path(s) to key the cache.
- registry-url: set up an npm registry for publishing with auth.
Example workflow
.github/workflows/ci.yml
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 testOn any runner
setup-node runs on any runner. Latchkey managed runners execute it unchanged, with the same caching, at a lower per-minute cost.
Key takeaways
- Pin node-version (or node-version-file) for reproducible builds.
- cache: npm avoids reinstalling unchanged dependencies.
- registry-url plus a token enables npm publish from CI.