~/
Install & Setup
Quiz
...

Install & Setup

beginner · updated Tue Sep 22 2026Contribute

Install Node.js, pick a version manager, and run your first script.

Install & Setup

Getting Node running takes a few minutes. Do it right once and you avoid version pain forever.

Check What You Have

Open a terminal and run:

node --version
npm --version

npm ships with Node, so you get both. If the commands are missing, install Node.

Use a Version Manager

Different projects need different Node versions. A version manager lets you switch instantly:

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

# fnm (fast, cross-platform)
brew install fnm

# Windows: use nvm-windows or fnm

Then install a current LTS release:

nvm install --lts
nvm use --lts

LTS (Long Term Support) is the stable choice for real projects.

Your First Script

Create a file called hello.js:

const name = process.argv[2] ?? "world";
console.log(`Hello, ${name}!`);

Run it:

node hello.js
node hello.js Ada

process.argv holds the command-line arguments. Index 2 is the first one you passed.

Initialize a Project

Every project should have a package.json. Generate one:

npm init -y

This records your dependencies and scripts. Run commands with:

npm run dev

Keep Node Out of Git

Add node_modules to .gitignore — dependencies are reinstallable from package.json.

node_modules/
.env

Best Practices

  1. Pin the version — Add an .nvmrc with 20 and commit it.
  2. Use LTS — Avoid odd-numbered and brand-new releases in production.
  3. Commit package-lock.json — It locks exact dependency versions.
  4. Never commit node_modules — Or .env files with secrets.

Common Mistakes

  1. Installing with sudo — It breaks permissions; use a version manager.
  2. Mixing managers — Pick nvm or fnm, not both.
  3. Ignoring engine warningsengines in package.json tells teammates the required version.
  4. Forgetting to restart the shell — Newly installed managers need a reload.