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@v7Inputs
| Name | Required | Default | Description |
|---|---|---|---|
node-version | No | none | Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0. |
node-version-file | No | none | File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions, mise.toml. |
architecture | No | none | Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default. |
check-latest | No | false | Set this option if you want the action to check for the latest available version that satisfies the version spec. |
registry-url | No | none | Optional 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. |
scope | No | none | Optional scope for authenticating against scoped registries. Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/). |
token | No | ${{ 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. |
cache | No | none | Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm. |
package-manager-cache | No | true | Set 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-path | No | none | Used 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. |
mirror | No | none | Used to specify an alternative mirror to download Node.js binaries from |
mirror-token | No | none | The token used as Authorization header when fetching from the mirror |
Outputs
| Name | Description |
|---|---|
cache-hit | A boolean value to indicate if a cache was hit. |
cache-primary-key | The key used to restore and save the cache. |
cache-matched-key | The key of the cache that was restored. Empty when no cache is found. |
node-version | The 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 testRead 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 buildEach 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.