Sets up Node.js environment and installs dependencies with automatic package manager detection, intelligent caching, and
dynamic Node version detection via the node-version input, .node-version, .nvmrc, or package.json volta.node.
This action provides the following functionality:
- Automatically detects package manager (npm, yarn, or pnpm) from lockfiles
- Uses GitHub's official
setup-nodeaction (v6) with optimized caching - Upgrades npm to v11 (pinned to
^11.5.1for OIDC trusted publishing support) - Installs dependencies with appropriate commands based on detected package manager
- Supports
.node-version,.nvmrc, andpackage.jsonvolta.nodefor version specification - Intelligent caching of node_modules when lockfiles are present
See action.yml.
steps:
- uses: actions/checkout@v6
# Will setup node, inferring node version from your codebase & installing your dependencies
- uses: codfish/actions/setup-node-and-install@v3
# Or if you want to be explicit
- uses: codfish/actions/setup-node-and-install@v3
with:
node-version: 24.4
- run: npm testThe node-version input is optional. If not supplied, this action will attempt to resolve a version using, in order:
.node-version, 2).nvmrc, 3)package.jsonvolta.node. If none are present,actions/setup-noderuns without an explicit version and will use its default behavior.
The install-options input is optional. If not supplied, the npm install commands will execute as defined without any
additional options.
With .nvmrc file
# .nvmrc
v18.14.1steps:
- uses: actions/checkout@v6
# will install Node v18.14.1
- uses: codfish/actions/setup-node-and-install@v3
- run: npm testWith .node-version file
# .node-version
20.10.0steps:
- uses: actions/checkout@v6
# will install Node v20.10.0
- uses: codfish/actions/setup-node-and-install@v3
- run: npm testWhen multiple version specification methods are present, the action uses this priority order:
- Input parameter (
node-version) - highest priority .node-versionfile.nvmrcfilepackage.jsonvolta.nodepropertyactions/setup-nodedefault behavior when no version is specified
| Input | Description | Required | Default |
|---|---|---|---|
node-version |
Node.js version to install (e.g. "24", "lts/*"). Precedence: node-version input > .node-version > .nvmrc > package.json volta.node. | No | - |
install-options |
Extra command-line options to pass to npm/pnpm/yarn install. | No | - |
working-directory |
Directory containing package.json and lockfile. | No | . |
registry-url |
Optional registry URL to configure for publishing (e.g. "https://registry.npmjs.org/"). Creates .npmrc with NODE_AUTH_TOKEN placeholder. NOT recommended if using semantic-release (it handles auth independently). Only needed for publishing with manual npm publish or other non-semantic-release workflows. | No | - |
upgrade-npm |
Whether to upgrade npm to v11.5.1. This is required for OIDC trusted publishing but can be disabled if you want to shave off some run time and you are still using token-based authentication. | No | true |
The action automatically detects your package manager:
- pnpm: Detected when
pnpm-lock.yamlexists - yarn: Detected when
yarn.lockexists - npm: Detected when
package-lock.jsonexists or as fallback
This action automatically upgrades npm to v11 after Node.js setup (pinned to ^11.5.1). This ensures:
- npm 11.5.1+ is available for OIDC trusted publishing support (required as of January 2026)
- Stable, predictable npm behavior across workflows
- Security fixes and improvements within the v11 release line
- No unexpected breaking changes from major version updates
The upgrade happens transparently and is logged in the workflow output. The version is pinned to prevent unexpected breaking changes while still receiving patch and minor updates within v11.
The registry-url input configures npm authentication by creating a .npmrc file with a NODE_AUTH_TOKEN placeholder.
In most cases, you should NOT set this parameter.
Skip this parameter if:
- You're only installing dependencies (the primary use case for this action) - authentication is not needed for public packages
- You're using semantic-release for publishing - it handles npm authentication independently and
registry-urlcan cause conflicts (semantic-release docs) - You're using OIDC trusted publishing with npm - the upgraded npm v11 handles this automatically
Only set this parameter if:
- You're publishing to npm using manual
npm publish(not semantic-release) - You need to authenticate to a private npm registry
- You're using legacy token-based publishing and need the
.npmrcfile created
- uses: codfish/actions/setup-node-and-install@v3
with:
registry-url: 'https://registry.npmjs.org/'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm publish- uses: codfish/actions/setup-node-and-install@v3
with:
node-version: '18'- uses: codfish/actions/setup-node-and-install@v3
with:
working-directory: './frontend'
install-options: '--frozen-lockfile'Replace multiple setup steps with this single action:
- - uses: actions/setup-node@v4
- with:
- node-version-file: '.nvmrc'
- cache: 'npm'
- - run: npm ci --prefer-offline --no-audit
+ - uses: codfish/actions/setup-node-and-install@v3