Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Node.js, npm and Version Managers

Install Node.js and npm, check versions, understand LTS releases, switch Node versions with nvm or fnm, and enable Yarn and pnpm through Corepack.

npm is bundled with Node.js, so installing Node gives you the node and npm commands in one step. Yarn and pnpm are separate programs, but modern Node setups can provision them through a tool called Corepack. This lesson walks through installing and checking your tools, choosing a Node version, and keeping several versions side by side.

Installing Node.js

Download the LTS installer for your system from the official Node.js website, or use your system's package manager. LTS means long-term support: even-numbered major releases become LTS in the autumn and receive security fixes for about three years. Use LTS for real projects. The "Current" line gets new features first but is shorter-lived.

After installing, open a new terminal and check:

Terminal
node --version    # for example v24.x
npm --version     # for example 11.x

If both print a version, you are ready. If the shell says "command not found", the installer's folder is not on your PATH; open a fresh terminal or sign out and in.

Each Node release bundles a specific npm. You can update npm separately, but there is rarely a need:

Terminal
npm install --global npm@latest   # updates npm itself (may need admin rights)

Packages can also declare which Node versions they support in an engines field, which you will meet in package.json Fields.

Reading process.versions

Node exposes its own version at runtime, which is handy for diagnostics and bug reports.

Node.js Which Node am I running?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

When a script runs through npm run, the variable npm_config_user_agent contains something like npm/11.0.0 node/v24.0.0 linux x64. Yarn and pnpm set it too, which is how tools detect which manager started them.

Why you may need several Node versions

One project may need Node 20, another Node 24. A version manager installs many versions and switches between them per terminal or per project.

  • nvm (Node Version Manager) is the long-standing choice on macOS and Linux. On Windows, use nvm-windows.
  • fnm (Fast Node Manager) is a cross-platform alternative written in Rust, popular for its speed.
  • Volta pins the Node version in package.json and switches automatically.

Typical nvm usage (read-only):

Terminal
nvm install 24      # download Node 24
nvm use 24          # switch this terminal to it
nvm alias default 24

Many teams commit a file called .nvmrc (or .node-version) containing just 24. Tools like nvm and fnm read it, so every developer gets the same major version.

Checking a version requirement in code

A script can verify that the running Node satisfies a minimum. This stand-in mimics the check that engines enforces:

Node.js A minimum Node version check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Comparing numbers piece by piece (not as strings) matters: as text, "9" sorts after "10". You will see this again in Semantic Versioning.

Corepack: Yarn and pnpm without a separate install

Corepack is a small launcher that downloads the exact Yarn or pnpm version a project asks for. It reads the packageManager field from package.json.

Terminal
corepack enable                # once per Node installation
JSON
{
  "name": "my-app",
  "packageManager": "[email protected]"
}

With that field present and Corepack enabled, typing pnpm install uses the pinned version, and a teammate who types yarn install gets a helpful error. In recent Node releases Corepack is no longer bundled by default, so you may need npm install --global corepack first; check the release notes of your Node version.

Where things live

Node.js Where would npm put things?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The exact global location depends on how Node was installed; npm config get prefix prints yours. Global installs are covered in Global Installs and npx.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which Node.js release line should you pick for a production project?

    LTS releases are stable and receive security fixes for years.
  2. 2. What does a file named .nvmrc usually contain?

    Version managers read .nvmrc to switch to the requested Node version.
  3. 3. What does Corepack do?

    Corepack reads the packageManager field and provisions the exact tool and version.
  4. 4. Why compare versions numerically, not as text?

    Text order puts '9' after '10', which gives the wrong answer for version numbers.

Summary

  • Installing Node.js also installs npm; prefer an LTS release.
  • node --version and npm --version check your setup; process.version does the same inside code.
  • nvm, fnm and Volta switch between Node versions; .nvmrc records the version for a project.
  • Corepack provides pinned Yarn and pnpm versions via the packageManager field.
  • Compare versions part by part, as numbers.

Next: npm, Yarn and pnpm Compared