Node.js how-to

How to Check Node Version (and Switch or Pin It)

Most Node.js problems that look mysterious come from the wrong runtime version: the laptop runs one major, the container runs another, and CI runs a third. This guide shows how to check the version in use, how to read the release numbers, and how to switch and pin a version so every environment runs the same one.

By Jasdeep Bains, SeaGit

·

Key takeaways

  • Run node -v to see the version the shell uses. The number that matters is the major, such as 22 or 24.
  • Even-numbered majors become LTS. Odd-numbered majors are Current only and never reach LTS.
  • Pin one major per project with a .nvmrc file, an engines field, and the same major in your Dockerfile and CI.
  • If the version changes after you install something, the cause is almost always PATH order or a shell that did not load your version manager.

Check the Node.js and npm version

Open a terminal and run the command below. Both spellings return the same answer, so use whichever you remember.

bash
node -v            # same as: node --version
npm -v             # npm ships with Node but has its own version number
node -p process.versions.node   # the full version, e.g. 24.1.0
node -p process.versions.v8     # the bundled V8 engine version
node -v prints a leading v. The -p flag evaluates an expression and prints it, so it works without a script file.

Inside application code, read the same value from the runtime. This is useful for a startup log line or a health endpoint that reports which runtime is serving traffic.

js
console.log(process.version);          // "v24.1.0"
console.log(process.versions.node);    // "24.1.0"
console.log(process.versions.v8);      // V8 engine version
process.version includes the leading v. process.versions.node does not.

What the version numbers mean

A Node.js version has three parts: major, minor and patch. 24.1.0 is major 24, minor 1, patch 0. Compatibility decisions, such as which packages install and which language features exist, depend on the major. Minor and patch releases are meant to be safe within a major.

Each major moves through release phases. Current receives most non-breaking changes. Active LTS gets features and fixes that the release team has judged stable. Maintenance gets only critical fixes and security updates. The release team sets these dates in the nodejs/release schedule.

Release lines and what to choose

PhaseWhat it means for you
CurrentNewest features. Good for trying things, usually not the line to run in production.
Active LTSThe default choice for a new production service.
MaintenanceSecurity and critical fixes only. Plan a move to a newer LTS before end-of-life.

Even-numbered majors enter LTS, and odd-numbered majors do not. As of October 2026, the schedule lists 24.x as Active LTS, 22.x as Maintenance and 26.x as Current. Check the live table at github.com/nodejs/release before you commit to a line, because the dates can change.

Switch between Node versions

A version manager installs several majors side by side and points node at one of them. Pick one tool and use it everywhere. nvm is the most common on macOS and Linux.

bash
# nvm (macOS, Linux, WSL)
nvm install --lts          # install the current Active LTS
nvm install 24             # install the latest 24.x
nvm use 24                 # switch this shell to 24.x
nvm ls                     # list installed versions
nvm alias default 24       # new shells start on 24.x
nvm current                # print the version in use
nvm use with no argument reads .nvmrc in the current directory. The nvm README documents this behaviour.

Other tools

  • nvm-windows is a separate project from nvm. It does not read .nvmrc automatically, so run nvm use 24.1.0 with the exact version. Use nvm list to see what is installed.
  • fnm is a fast Rust-based manager. Run fnm install 24, fnm use 24 and fnm default 24. Add eval "$(fnm env --use-on-cd)" to your shell profile so it switches when you cd into a project that has a .nvmrc or .node-version file.
  • Volta installs tools per project. Run volta install node@24 to add it to your user toolchain, then volta pin node@24 inside a project to write the version into package.json.
  • Corepack ships with Node 16.9 and later. It manages the package managers pnpm and yarn, and it can pin them with the packageManager field. It does not install or switch Node itself. Run corepack enable to turn it on.

Pin one Node version for a project

A pin is a file in the repository that names the major everyone should run. Put one in place, then make the Dockerfile and the CI workflow read the same value.

bash
# .nvmrc (read by nvm and fnm)
echo "24" > .nvmrc

# .node-version (read by fnm, and by many other tools)
echo "24" > .node-version

# Volta: writes a "volta" block into package.json
volta pin node@24
Use a major such as 24 for the pin. A full version like 24.1.0 is stricter but you must update it on every patch.

Enforce it with engines

The engines field in package.json documents the range a package supports. By default npm only warns when the running version does not match. Set engine-strict in .npmrc to make npm install fail instead.

json
{
  "name": "my-app",
  "engines": {
    "node": ">=22 <27"
  }
}
Put engine-strict=true in the project .npmrc file. Pick a range that matches the lines you actually support.

Set the version in Docker and GitHub Actions

In a container, the Node version is whatever the FROM line names. Pin a major tag so a rebuild does not silently jump to a new major. For a production image that must never change, pin the digest as well.

dockerfile
# Pin the major and a variant
FROM node:24-bookworm-slim

# Stricter: pin the image digest too
# FROM node:24-bookworm-slim@sha256:<digest>

WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "server.js"]
Avoid node:latest. It moves to a new major without warning. Check the variant tags on the official node image on Docker Hub.

In GitHub Actions, actions/setup-node can read the version straight from the pin file, so the workflow and your local machine stay aligned.

yaml
steps:
  - uses: actions/checkout@v7
  - uses: actions/setup-node@v7
    with:
      node-version-file: '.nvmrc'
      cache: npm
  - run: npm ci
  - run: npm test
node-version-file accepts .nvmrc, .node-version and package.json. Use one source of truth.

Troubleshoot the wrong or missing version

Start with two commands. which node shows the file the shell is running, and node -v shows its version. On Windows, use where node in place of which node.

bash
which node          # path of the node binary in use
type -a node        # every node on PATH, in order
node -v             # the version of that binary
type -a lists all matches. The first line is the one that runs.
  • command not found: node. The version manager is installed but not loaded in this shell. Open a new terminal, or source the manager in your profile, then run nvm use 24 again.
  • Version changed after a Homebrew or installer update. A Homebrew or system Node earlier on PATH is shadowing nvm. Check type -a node, then put the version manager directory first or remove the old install.
  • Shell still reports the old version after nvm use. Run hash -r in bash or zsh to clear the cached path of the binary.
  • Node version differs between CI and local. CI is not reading your pin. Check that node-version-file points at the right file, and that the Dockerfile FROM line uses the same major.
  • No version switch on cd. The project has no .nvmrc or .node-version file, or the shell hook for fnm or nvm is not in your profile.
  • npm install fails with an engines error. engine-strict is on and the running version is outside the range in package.json. Switch to a supported version, or widen the range only after you have tested it.

How SeaGit picks the Node version

SeaGit builds apps from GitHub on push and deploys them to Amazon EKS in your own AWS account. Only AWS is supported as a target. A container build uses the Dockerfile at the repository root, so the Node version comes from that file. Set the FROM line to the major you want, and the build uses the same runtime as your pin file.

If the repository has no Dockerfile at the root, the default build fails with a message saying no Dockerfile was found. Add one, then push again to start a new build.

Frequently asked questions

How to Check Node Version (and Switch or Pin It): FAQ

Which command shows the Node.js version?

Run node -v or node --version. Both print the version of the node binary that the shell finds first on PATH. For npm, run npm -v.

Is an odd-numbered Node.js release an LTS release?

No. Only even-numbered majors enter LTS. Odd-numbered majors stay in Current and are supported for a shorter period. For a production service, choose an Active LTS line.

What is the difference between .nvmrc and engines?

.nvmrc tells a version manager which version to switch to. engines in package.json documents the supported range, and it only blocks installs when engine-strict is set in .npmrc. Use both for a project that needs a consistent runtime.

Does corepack change my Node version?

No. Corepack manages package managers such as pnpm and yarn. It does not install or switch the Node.js runtime, so you still need a version manager or a Docker image for that.

Why does my container run a different Node version from my laptop?

The container uses the FROM line in the Dockerfile, not your local install. Set the same major in .nvmrc, in the Dockerfile and in the CI workflow so all three match.

Should I pin a full version or only a major?

Pin the major, such as 24, in most projects. It receives patch and security updates without a change to your files. Pin an exact version or a digest only when you need a build that never changes.

Sources

Checked 12 October 2026.

  1. Node.js: Downloads and previous releases — Release lines, version numbers and the phase each major is in.
  2. nodejs/release: release schedule — Release phases, the even-numbered LTS rule and the dates for Current, Active LTS and Maintenance.
  3. nvm-sh/nvm README — Install, nvm use, nvm alias default and .nvmrc handling.
  4. actions/setup-node README — node-version-file input and the sources it reads.
  5. Docker Hub: official node image — Tag and variant names for the official Node.js image.

Read next