Rana Maninder Singh
Lesson 7 of 8Setup Guide

Installation: Node.js & npm

Lesson opener

In one line: Install Node.js (the JavaScript runtime) and confirm npm (its package manager) works from a normal terminal. You will not write a web app here - you are installing the tool that the JavaScript course and npx-based helper.

Why it matters: This shows up at work when you need to install Node.js (the JavaScript runtime) and confirm npm (its package manager) works from a normal terminal. You will not write a web app here - you are installing the tool that the

Before this lesson: Organising an analysis project

Before you start

ResourceLink
PreviousOrganising an analysis project
NextDocker Desktop install
Time~20 minutes
What you needA computer where you can install software (Windows steps below; Mac notes included)

What you will learn

Install Node.js (the JavaScript runtime) and confirm npm (its package manager) works from a normal terminal. You will not write a web app here — you are installing the tool that the JavaScript course and npx-based helpers assume. A failed install later is almost always a PATH problem, so this lesson ends by proving your terminal can run node, npm, and npx from any folder.

Tutorial 1 — Install Node.js (the LTS line)

  1. Open nodejs.org and download the LTS installer for your machine. LTS (Long-Term Support) is the branch enterprises run; the "Current" branch moves faster and is not what this site uses.
  2. Run the installer. On Windows: leave the defaults, including Add to PATH. That checkbox is what makes node work from any terminal — the single most common Windows failure is unchecking it.
  3. Finish the installer. No reboot is normally needed.

Mac: the official .pkg installer adds node to /usr/local/bin automatically. If you prefer a version manager, Homebrew (brew install node@lts) or fnm work too — but for this course the official installer is enough.

This installer includes npm, so you get both tools at once. There is no separate npm download.


Tutorial 2 — Prove the install from a fresh terminal

Close and reopen your terminal before testing. Windows updates PATH only for new terminal sessions — an already-open window will still say node is not a command.

Run all three checks:

node --version
npm --version
npx --version

You want three version lines, for example:

v22.14.0
11.2.0
11.2.0

Expected result: three version strings, no "not recognized" errors. If node fails but npm works (or vice-versa), PATH was updated partway — reopen the terminal, and if it still fails, re-run the installer and confirm Add to PATH.

The version numbers do not need to match the example. Any recent LTS is fine for this course.


Tutorial 3 — What npx is for

npx lets you run a tool without permanently installing it. Web tutorials use it constantly (npx create-expo-app, npx playwright, …). It is not a separate download — it ships with npm.

npx --yes cowsay "hello from this course"

You should see a cow repeating your message. Running a one-off through npx beats npm install -g because the tool does not stay on your machine forever and does not fight with other projects over versions.

Use this when: a tutorial says npx <something> — run it as written instead of installing that package globally.


Tutorial 4 — Version pinning for a project

A Node project records its language version in a package.json engines field. When the JavaScript course asks you to create one, it will look like:

{
  "name": "learnings-js",
  "private": true,
  "engines": {
    "node": ">=22 <25"
  }
}

>=22 <25 says: any Node 22 LTS or newer LTS (24), but not the moving "Current" line. When a later developer runs npm install, npm does not rewrite your project's code for a different Node major.


Essential commands

Command / actionWhat it does
node --versionPrints the installed Node.js version
npm --versionPrints the bundled npm version
npx --versionPrints the bundled npx version (ships with npm)
node -e "console.log(1+1)"Runs a one-line JavaScript program without a file
npx <tool>Runs a tool once without a global install

Practice

Do this now:

  1. Install the LTS Node.js from nodejs.org with PATH enabled.
  2. Reopen your terminal and run node --version, npm --version, npx --version — all three must print a version.
  3. Run node -e "console.log('node works')" and confirm node works appears.
  4. Optional but useful: npx --yes cowsay "ready" — you now know how one-off tools are run.

Teacher walkthrough: LTS, then project local installs

All figures illustrative.

Step 1 — Install Node LTS; node --version / npm --version.

Step 2 — Prefer project-local packages (npm install in the app folder) over random globals.

Step 3 — Scripts via npm run … as the project defines.

Step 4 — Lockfile committed when the project has one.

Failure example: global package version fights the project

Symptom: Works on one machine, fails on another; "command not found" for local bins.

Diagnosis: Global install / wrong cwd / not using npx or npm scripts.

Correction: cd to project; install from package.json; use npx/npm run.

Validation: Documented script exits 0 on a clean clone after npm install.

Guided practice

Why commit package-lock.json (when present) for class projects?

Complete solution: Locks dependency versions so teammates and CI install the same tree.

Independent practice

Acceptance criteria:

Common mistakes

  1. Installing everything with -g by habit.
  2. Deleting the lockfile to "fix" conflicts blindly.
  3. Using an ancient Node while Expo/RN require LTS.

Checklist

  • [ ] node --version prints a version in a fresh terminal
  • [ ] npm --version and npx --version print versions too
  • [ ] node -e "..." runs a one-liner
  • [ ] I can distinguish LTS from "Current" and know which this course uses
  • [ ] Ready for Docker Desktop install, then the JavaScript course

Verified against tool install guides on this site documentation, September 2026.