Node.js Installation

Node.js comes bundled with npm. You need Node.js to run most modern JavaScript tooling, including React projects built with Vite or Create React App.

nvm (Node Version Manager) lets you install multiple Node versions and switch between them. This is the approach most developers use because projects sometimes require different Node versions.

# macOS / Linux: install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

After installing, close and reopen your terminal, then:

nvm install --lts   # install the latest LTS version
nvm use --lts       # switch to it
nvm ls              # list installed versions

Alternative: download from nodejs.org

Go to nodejs.org and download the LTS release. LTS (Long Term Support) is the stable version recommended for most projects. The Current release has the latest features but is less stable.

Alternative for macOS: Homebrew

brew install node

This installs the current version, not a specific LTS release.

Verify your install

node -v   # should print something like v22.x.x
npm -v    # should print something like 10.x.x

Install nodemon for development

Nodemon watches your files and restarts the Node process automatically when a file changes. Without it, you would need to stop and restart the server manually after every code change.

Install it as a dev dependency (it is only needed during development, not in production):

npm install -D nodemon

Add a dev script to your package.json:

{
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  }
}

Then run npm run dev to start the server with auto-restart enabled.

  • Running Node.js : how to run scripts and use the REPL
  • npm : managing packages and dependencies