actions/setup-node@v7

Setup a Node.js environment by adding problem matchers and optionally downloading and adding it to the PATH.

At a glance

Latest major
v7
Repository
actions/setup-node
Inputs
12 (0 required)
Outputs
4
Runs using
node24
License
MIT
Last checked

Inputs and outputs come straight from the action's official action.yml. See our editorial standards.

Usage

- uses: actions/setup-node@v7

Inputs

NameRequiredDefaultDescription
node-versionNononeVersion Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.
node-version-fileNononeFile containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions, mise.toml.
architectureNononeTarget architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
check-latestNofalseSet this option if you want the action to check for the latest available version that satisfies the version spec.
registry-urlNononeOptional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.
scopeNononeOptional scope for authenticating against scoped registries. Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
tokenNo${{ github.server_url == 'https://github.com' && github.token || '' }}Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
cacheNononeUsed to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.
package-manager-cacheNotrueSet to false to disable automatic caching. By default, caching is enabled when either devEngines.packageManager or the top-level packageManager field in package.json specifies npm as the package manager.
cache-dependency-pathNononeUsed to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.
mirrorNononeUsed to specify an alternative mirror to download Node.js binaries from
mirror-tokenNononeThe token used as Authorization header when fetching from the mirror

Outputs

NameDescription
cache-hitA boolean value to indicate if a cache was hit.
cache-primary-keyThe key used to restore and save the cache.
cache-matched-keyThe key of the cache that was restored. Empty when no cache is found.
node-versionThe installed node version.

Read an output with ${{ steps.<step-id>.outputs.<name> }}; the step needs an id.

Examples

Node with the npm cache

The usual CI start: a pinned Node major plus the package-manager cache.

name: Example
on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Setup Node.js environment
        uses: actions/setup-node@v7
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm test

Read the version from .nvmrc and publish to npm

Keep one source of truth for the Node version and write the .npmrc registry line that later npm commands use.

name: Example
on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Setup Node.js environment
        uses: actions/setup-node@v7
        with:
          node-version-file: .nvmrc
          registry-url: "https://registry.npmjs.org"
      - run: npm ci
      - run: npm run build

Each example passed actionlint (syntax, expressions and the inputs it knows for this action). They were not run in a live repository, so replace placeholder values such as names, ARNs and paths with your own.

Something out of date or wrong? Report it on our Contact page. This page is rebuilt from the action's repository roughly once a week.