Skip to content
Latchkey

How to Use the Built-in cache Input of setup-node

setup-node caches the package manager store for you when you set cache: npm, yarn, or pnpm.

Instead of a separate actions/cache step, set cache: on actions/setup-node. It locates the lockfile, picks the right store path, and keys the cache on the lockfile hash automatically.

Steps

  • Add cache: npm (or yarn, pnpm) to the setup-node with block.
  • Point cache-dependency-path at the lockfile in a monorepo subdir if needed.
  • Run your normal clean install after the setup step.

Workflow

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-node@v4
    with:
      node-version: 20
      cache: npm
      cache-dependency-path: apps/web/package-lock.json
  - run: npm ci

Gotchas

  • For pnpm, run pnpm/action-setup before setup-node so the binary exists.
  • The built-in cache keys only on the lockfile; use raw actions/cache for custom paths.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →