Skip to content

Node.js Setup

Getting a reliable Node.js setup matters more than it seems, version mismatches cause a huge share of "it works on my machine" bugs. This lesson covers installing Node.js, managing versions, and creating your first project.

Installing Node.js

Node.js ships in two release lines: an even-numbered LTS (Long-Term Support) version recommended for most production and learning use, and a current/odd-numbered version with the newest features but a shorter support window. For tutorials and production apps alike, install the active LTS release.

You can install Node.js directly from nodejs.org, through your OS package manager, or, best for day-to-day development, through a version manager like nvm (Node Version Manager) that lets you install and switch between multiple Node.js versions per project.

# install nvm, then install and use an LTS version
nvm install --lts
nvm use --lts

node --version
npm --version

After installing, both node and npm (Node's bundled package manager) should print version numbers. If either command is not found, your shell's PATH is not picking up the installation.

Starting a New Project

mkdir my-app
cd my-app
npm init -y
node --version >> .nvmrc   # optional: pin the Node version for this project
  • npm init -y creates a package.json with default values.
  • A .nvmrc file lets teammates run nvm use to match your Node.js version automatically.
  • Most editors (VS Code, Cursor) detect package.json and enable JavaScript/TypeScript tooling automatically.

Node.js Setup Commands

Commands you will use whenever you install Node.js or start a new project.

Command Purpose
nvm install --lts Install the latest LTS Node.js version
nvm use 22 Switch the current shell to Node.js 22
nvm ls List installed Node.js versions
node --version Print the active Node.js version
npm init -y Create a default package.json
npm install Install dependencies listed in package.json

Choosing an LTS Version

Node.js release lines follow an even/odd pattern: even-numbered major versions (18, 20, 22, 24...) become LTS releases with roughly 30 months of support, while odd-numbered versions are short-lived "current" releases meant for early adopters. Unless you specifically need a bleeding-edge feature, install the active LTS.

  • LTS versions get security and bug fixes for years, ideal for production.
  • Current/odd versions preview upcoming features but lose support quickly.
  • Check package.json's engines field in existing projects before assuming a version.

Managing Multiple Versions With nvm

Real teams work across projects that require different Node.js versions. A version manager avoids the pain of a single global installation by letting you switch versions instantly, per shell session or per project folder.

nvm install 20
nvm install 22
nvm use 20
node --version   # v20.x.x

nvm use 22
node --version   # v22.x.x

Combine this with a .nvmrc file containing just the version number (e.g. 22) in each project so nvm use picks the right version automatically.

Common Mistakes

  • Installing Node.js through multiple methods (installer + nvm + package manager) at once, causing PATH conflicts.
  • Using an odd-numbered "current" release in production instead of the LTS line.
  • Forgetting to run nvm use in a new terminal tab, silently falling back to the system default version.
  • Skipping npm init, then manually hand-writing an invalid package.json.

Key Takeaways

  • Install the active LTS release of Node.js for most learning and production work.
  • A version manager like nvm lets you switch Node.js versions per project instantly.
  • .nvmrc files help teams stay on the same Node.js version.
  • npm init -y is the fastest way to scaffold a new project's package.json.

Pro Tip

Commit a .nvmrc (and an engines field in package.json) to every project. It costs one file and eliminates an entire category of "works on my machine" bugs caused by Node.js version drift.