Convert Figma logo to code with AI

actions logosetup-node

Set up your GitHub Actions workflow with a specific version of node.js

4,619
1,619
4,619
98

Top Related Projects

9,719

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.

39,619

An extremely fast bundler for the web

115,143

Node.js JavaScript runtime ✨🐢🚀✨

105,052

A modern runtime for JavaScript and TypeScript.

88,960

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

12,608

Volta: JS Toolchains as Code. ⚡

Quick Overview

The actions/setup-node GitHub Action is a tool that sets up a Node.js environment on a GitHub Actions runner, allowing you to run Node.js-based scripts and applications as part of your CI/CD workflow. It supports multiple versions of Node.js and can be configured to install additional tools and dependencies.

Pros

  • Cross-platform support: The action works on Windows, macOS, and Linux, making it suitable for a wide range of projects.
  • Version management: You can easily specify the desired version of Node.js to be installed, including specific patch versions.
  • Additional tools and dependencies: The action allows you to install additional tools and dependencies, such as npm packages, to customize the environment.
  • Caching: The action supports caching of the installed Node.js version and npm packages, improving build times.

Cons

  • Limited control: While the action provides a convenient way to set up a Node.js environment, it may not offer the same level of control as manually configuring the environment.
  • Dependency on GitHub Actions: The action is designed to be used within the GitHub Actions ecosystem, so it may not be suitable for projects that don't use GitHub Actions.
  • Potential version conflicts: If your project requires a specific version of Node.js or npm, the action may not always provide the exact version you need.
  • Potential maintenance issues: As with any third-party tool, there is a risk of the action becoming outdated or unsupported over time.

Code Examples

N/A (This is not a code library)

Getting Started

N/A (This is not a code library)

Competitor Comparisons

9,719

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.

Pros of ncc

  • Compiles Node.js projects into single files, reducing deployment size
  • Eliminates need for node_modules in production environments
  • Faster execution due to bundled dependencies

Cons of ncc

  • May encounter issues with dynamic imports or certain packages
  • Requires additional build step in development workflow
  • Less flexibility for runtime dependency updates

Code Comparison

setup-node:

- uses: actions/setup-node@v3
  with:
    node-version: '14'
- run: npm ci
- run: npm run build

ncc:

- run: npm i -g @vercel/ncc
- run: ncc build index.js -o dist
- uses: actions/upload-artifact@v2
  with:
    name: dist
    path: dist

Summary

setup-node is ideal for standard Node.js setups, providing easy version management and dependency installation. ncc excels in creating compact, self-contained Node.js applications, particularly useful for serverless deployments or environments with limited storage. While setup-node offers more flexibility, ncc can significantly reduce deployment size and improve startup times at the cost of a slightly more complex build process.

39,619

An extremely fast bundler for the web

Pros of esbuild

  • Extremely fast JavaScript bundler and minifier
  • Supports modern JavaScript features out of the box
  • Minimal configuration required for most use cases

Cons of esbuild

  • Limited plugin ecosystem compared to other bundlers
  • May not support all advanced bundling scenarios
  • Less suitable for non-JavaScript assets

Code Comparison

setup-node:

- uses: actions/setup-node@v3
  with:
    node-version: '14'

esbuild:

const esbuild = require('esbuild')

esbuild.build({
  entryPoints: ['app.js'],
  outfile: 'out.js',
  bundle: true,
  minify: true,
})

Key Differences

  • setup-node is a GitHub Action for setting up Node.js environments in workflows
  • esbuild is a JavaScript bundler and minifier tool
  • setup-node is used for CI/CD processes, while esbuild is used in build processes
  • setup-node doesn't directly affect code, whereas esbuild processes and transforms JavaScript code

Use Cases

  • Use setup-node when you need to set up a Node.js environment in GitHub Actions
  • Use esbuild when you need to bundle and minify JavaScript code quickly and efficiently
  • setup-node is often used in combination with other build tools, including esbuild
115,143

Node.js JavaScript runtime ✨🐢🚀✨

Pros of node

  • Full Node.js runtime implementation, offering complete control and customization
  • Allows for deep understanding and modification of Node.js internals
  • Suitable for contributing to Node.js development or creating custom builds

Cons of node

  • Significantly larger and more complex, requiring more resources to work with
  • Not designed for quick setup in CI/CD environments or GitHub Actions
  • Steeper learning curve for those only needing to use Node.js in workflows

Code Comparison

setup-node:

- uses: actions/setup-node@v3
  with:
    node-version: '14'

node:

git clone https://github.com/nodejs/node.git
cd node
./configure
make -j4
make install

The setup-node action is designed for quickly setting up Node.js in GitHub Actions workflows, while the node repository is the full Node.js runtime implementation. setup-node is more suitable for most CI/CD scenarios, offering a simple way to specify and use different Node.js versions. The node repository is better suited for developers working on Node.js itself or requiring custom builds.

105,052

A modern runtime for JavaScript and TypeScript.

Pros of Deno

  • Built-in TypeScript support without additional configuration
  • Improved security with explicit permissions for file, network, and environment access
  • Simplified dependency management with no need for a package.json file

Cons of Deno

  • Smaller ecosystem compared to Node.js, with fewer available packages
  • Limited compatibility with existing Node.js projects and libraries
  • Steeper learning curve for developers already familiar with Node.js

Code Comparison

setup-node:

- uses: actions/setup-node@v3
  with:
    node-version: '14'
- run: npm install
- run: npm test

Deno:

- uses: denoland/setup-deno@v1
  with:
    deno-version: v1.x
- run: deno test

The Deno setup is more straightforward, requiring fewer steps due to its built-in package management and testing capabilities. However, the setup-node action offers more flexibility for complex Node.js projects with specific npm-based workflows.

88,960

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Pros of nvm

  • Allows managing multiple Node.js versions on a single machine
  • Provides a more flexible environment for local development
  • Supports a wider range of Node.js versions and distributions

Cons of nvm

  • Requires manual installation and setup on CI/CD systems
  • May introduce complexity in CI/CD pipelines
  • Slower to set up compared to GitHub Actions

Code Comparison

setup-node:

steps:
- uses: actions/setup-node@v3
  with:
    node-version: '14'

nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 14
nvm use 14

Summary

setup-node is designed specifically for GitHub Actions, offering seamless integration and faster setup times in CI/CD environments. It's ideal for projects with straightforward Node.js version requirements.

nvm provides more flexibility and control over Node.js versions, making it better suited for local development and projects requiring multiple Node.js versions. However, it requires more setup in CI/CD pipelines and may introduce additional complexity.

Choose setup-node for simpler CI/CD workflows, and nvm for more complex local development environments or when greater version control is needed.

12,608

Volta: JS Toolchains as Code. ⚡

Pros of Volta

  • Seamless version management across projects and developers
  • Faster installation and switching between Node.js versions
  • Supports pinning tool versions in project files for consistency

Cons of Volta

  • Limited platform support (primarily macOS and Linux)
  • Requires additional setup and learning curve for team adoption
  • May conflict with other Node.js version managers already in use

Code Comparison

setup-node:

- uses: actions/setup-node@v3
  with:
    node-version: '14'

volta:

- uses: volta-cli/action@v4
- run: volta install node@14

Key Differences

  • setup-node is specifically designed for GitHub Actions, while Volta is a general-purpose Node.js version manager that can be used in various environments.
  • Volta offers a more comprehensive approach to managing Node.js and related tools, including package managers and other binaries.
  • setup-node provides simpler integration with GitHub Actions workflows, requiring less configuration for basic use cases.

Use Cases

  • Choose setup-node for straightforward Node.js setup in GitHub Actions workflows, especially when working with multiple platforms.
  • Opt for Volta when you need consistent Node.js environments across local development and CI/CD pipelines, and want to manage multiple tools beyond just Node.js.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

setup-node

basic-validation versions e2e-cache proxy

This action provides the following functionality for GitHub Actions users:

  • Optionally downloading and caching distribution of the requested Node.js version, and adding it to the PATH
  • Optionally caching npm/yarn/pnpm dependencies
  • Registering problem matchers for error output
  • Configuring authentication for GPR or npm

Breaking changes in V5

  • Enabled caching by default with package manager detection if no cache input is provided.

    For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting package-manager-cache: false when caching is not needed for secure operation.

  • Upgraded action from node20 to node24.

    Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. See Release Notes

For more details, see the full release notes on the releases page

Usage

See action.yml

- uses: actions/setup-node@v5
  with:
    # Version Spec of the version to use in SemVer notation.
    # It also admits such aliases as lts/*, latest, nightly and canary builds
    # Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
    node-version: ''

    # File containing the version Spec of the version to use.  Examples: package.json, .nvmrc, .node-version, .tool-versions.
    # If node-version and node-version-file are both provided the action will use version from node-version. 
    node-version-file: ''

    # Set this option if you want the action to check for the latest available version 
    # that satisfies the version spec.
    # It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen). 
    # Default: false
    check-latest: false

    # Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
    # Default: ''. The action use system architecture by default 
    architecture: ''

    # Used to pull node distributions from https://github.com/actions/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.
    #
    # We recommend using a service account with the least permissions necessary. Also
    # when generating a new PAT, select the least scopes necessary.
    #
    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
    #
    # Default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
    token: ''

    # Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.
    # Package manager should be pre-installed
    # Default: ''
    cache: ''

    # Used to disable automatic caching based on the package manager field in package.json. By default, caching is enabled if the package manager field is present and no cache input is provided'
    # default: true
    package-manager-cache: true

    # Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. 
    # It will generate hash from the target file for primary key. It works only If cache is specified.  
    # Supports wildcards or a list of file names for caching multiple dependencies.
    # Default: ''
    cache-dependency-path: ''

    # 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.
    # Default: ''
    registry-url: ''

    # 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/).
    # Default: ''
    scope: ''

    # Set always-auth option in npmrc file.
    # Default: ''
    always-auth: ''

    # Optional mirror to download binaries from.
    # Artifacts need to match the official Node.js
    # Example:
    # V8 Canaray Build: <mirror_url>/download/v8-canary
    # RC Build: <mirror_url>/download/rc
    # Official: Build <mirror_url>/dist
    # Nightly build: <mirror_url>/download/nightly
    # Default: ''
    mirror: ''

    # Optional mirror token.
    # The token will be used as a bearer token in the Authorization header
    # Default: ''
    mirror-token: ''

Basic:

steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
  with:
    node-version: 18
- run: npm ci
- run: npm test

The node-version input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one.

The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from node-versions releases and on miss or failure will fall back to the previous behavior of downloading directly from node dist.

For information regarding locally cached versions of Node.js on GitHub hosted runners, check out GitHub Actions Runner Images.

Supported version syntax

The node-version input supports the Semantic Versioning Specification, for more detailed examples please refer to the semver package documentation.

Examples:

  • Major versions: 18, 20
  • More specific versions: 10.15, 16.15.1 , 18.4.0
  • NVM LTS syntax: lts/erbium, lts/fermium, lts/*, lts/-n
  • Latest release: * or latest/current/node

Note: Like the other values, * will get the latest locally-cached Node.js version, or the latest version from actions/node-versions, depending on the check-latest input.

current/latest/node always resolve to the latest dist version. That version is then downloaded from actions/node-versions if possible, or directly from Node.js if not. Since it will not be cached always, there is possibility of hitting rate limit when downloading from dist

Checking in lockfiles

It's always recommended to commit the lockfile of your package manager for security and performance reasons. For more information consult the "Working with lockfiles" section of the Advanced usage guide.

Caching global packages data

The action has a built-in functionality for caching and restoring dependencies. It uses actions/cache under the hood for caching global packages data but requires less configuration settings. Supported package managers are npm, yarn, pnpm (v6.10+). The cache input is optional.

Caching is turned on by default when a packageManager field is detected in the package.json file and no cache input is provided. The package-manager-cache input provides control over this automatic caching behavior. By default, package-manager-cache is set to true, which enables caching when a valid package manager field is detected in the package.json file. To disable this automatic caching, set the package-manager-cache input to false.

steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
  with:
    package-manager-cache: false
- run: npm ci

If no valid packageManager field is detected in the package.json file, caching will remain disabled unless explicitly configured. For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting package-manager-cache: false when caching is not needed for secure operation.

The action defaults to search for the dependency file (package-lock.json, npm-shrinkwrap.json or yarn.lock) in the repository root, and uses its hash as a part of the cache key. Use cache-dependency-path for cases when multiple dependency files are used, or they are located in different subdirectories.

Note: The action does not cache node_modules

See the examples of using cache for yarn/pnpm and cache-dependency-path input in the Advanced usage guide.

Caching npm dependencies:

steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
  with:
    node-version: 20
    cache: 'npm'
- run: npm ci
- run: npm test

Caching npm dependencies in monorepos:

steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
  with:
    node-version: 20
    cache: 'npm'
    cache-dependency-path: subdir/package-lock.json
- run: npm ci
- run: npm test

Matrix Testing

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [ 14, 16, 18 ]
    name: Node ${{ matrix.node }} sample
    steps:
      - uses: actions/checkout@v5
      - name: Setup node
        uses: actions/setup-node@v5
        with:
          node-version: ${{ matrix.node }}
      - run: npm ci
      - run: npm test

Using setup-node on GHES

setup-node comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Nodejs distributions, setup-node downloads distributions from actions/node-versions on github.com (outside of the appliance). These calls to actions/node-versions are made via unauthenticated requests, which are limited to 60 requests per hour per IP. If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: ##[error]API rate limit exceeded for.... After that error the action will try to download versions directly from the official site, but it also can have rate limit so it's better to put token.

To get a higher rate limit, you can generate a personal access token on github.com and pass it as the token input for the action:

uses: actions/setup-node@v5
with:
  token: ${{ secrets.GH_DOTCOM_TOKEN }}
  node-version: 20

If the runner is not able to access github.com, any Nodejs versions requested during a workflow run must come from the runner's tool cache. See "Setting up the tool cache on self-hosted runners without internet access" for more information.

Advanced usage

Recommended permissions

When using the setup-node action in your GitHub Actions workflow, it is recommended to set the following permissions to ensure proper functionality:

permissions:
  contents: read # access to check out code and install dependencies

License

The scripts and documentation in this project are released under the MIT License

Contributions

Contributions are welcome! See Contributor's Guide

Code of Conduct

:wave: Be nice. See our code of conduct