Chapter 2 of 18 · Node.js for Beginners — Complete Free Tutorial

Installing Node.js and Using the REPL

The Node.js for Beginners series continues with setup: a working install is the gate to every later chapter. You will pick a version strategy, install Node the safe way, verify it, and then meet the REPL — the instantly responding playground where you will test every idea in this course before putting it in a file.

Choosing an install method

There is no single correct way to install Node, but there is a correct principle: keep the runtime switchable so you can move between projects without breakage. A version manager makes that trivial.

MethodBest forWatch out for
nvm (macOS/Linux) / nvm-windowsLearners and professionals juggling projectsShell must be initialised in your profile
Official .pkg / .msi installerOne fixed version per machineUpgrades are manual; needs admin rights
Homebrew / apt / wingetQuick system-wide installsVersion may lag behind current LTS
Volta / asdfTool-chain managers that also pin npm toolsExtra concepts before your first script

Install and verify with nvm

On macOS or Linux, install nvm from its official repository, then ask for the long-term support release:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install --lts
nvm use --lts
node --version
npm --version

Expected output:

v24.6.0
11.3.0

If the installer route appeals instead, download the package from nodejs.org, run it, and verify with the same two commands. If either command says "command not found", restart the terminal first — that clears the PATH cache before you suspect a broken install.

LTS vs Current

  • LTS (Long Term Support) — stable, supported with security fixes for about 30 months. This is what production apps and this course use.
  • Current — the newest release with the latest features; expect occasional churn.
  • Odd-numbered releases — never enter LTS; they are short-lived stepping stones.

Rule of thumb: learn and ship on LTS, experiment on Current in a throwaway environment.

Meet the REPL

Running node with no file opens the REPL — Read-Eval-Print Loop. Type an expression, press Enter, and Node reads it, evaluates it, prints the result and waits again. It is the fastest feedback loop in the whole ecosystem.

node
> 2 + 2
4
> const price = 49.9
undefined
> `Total: $${price}`
'Total: $49.9'

Notice two REPL behaviours: assignments answer undefined (the value went into a variable, not to the printer), and evaluated template literals come back as strings with quotes — the REPL shows you the value it produced, exactly like a JavaScript console in the browser.

REPL dot commands

Dot commands are built-in utilities; .help lists them all.

CommandWhat it does
.helpShow every command with a description
.exitLeave the REPL (or press Ctrl+C twice)
.clearReset the context — drop all variables, stay open
.breakAbort a multi-line statement you are still typing
.save file.jsWrite the session to a file you can run later

Practical things to try

The REPL is also a probe for your machine and for built-ins. A short session:

> require('os').platform()
'darwin'
> process.env.HOME || process.env.USERPROFILE
'/Users/asha'
> typeof fetch
'function'
> await fetch('https://example.com').then(r => r.status)
200

Expected output: platform name, your home directory, and confirmation that modern Node includes a global fetch — no library required. Top-level await works in the REPL even in CommonJS mode, which makes it ideal for probing promises.

Common mistakes

  • Installing Current for work — features may vanish or change; LTS is the safe default.
  • Forgetting to restart the terminal — new PATH entries are not read by shells already running.
  • Pasting multi-line code into the REPL — it can mis-parse; save to a file and run node file.js instead.
  • Treating REPL output as gospel — objects print with formatting that hides detail; use console.log() or util.inspect() for the truth.
  • Leaving stray REPL sessions open — they hold variables and keep a shell busy; .exit or Ctrl+C when done.

Practice checklist

  1. Install an LTS version with your chosen method and record node --version and npm --version.
  2. Open the REPL and evaluate five expressions, including one array method and one string method.
  3. Run .help, then practice .clear and .break so you can escape a bad paste.
  4. Use .save first-session.js, exit, then run the saved file with node first-session.js.
  5. Verify typeof fetch on your machine and note the result.

The REPL is for experiments — real programs live in files. Next: Running JavaScript in Node.

Quiz: Installing Node.js and Using the REPL

5 questions · 70% to pass

Frequently Asked Questions

Node.js is a runtime that executes JavaScript outside the browser. It combines Google's V8 engine with APIs for files, networks, processes and streams, plus a package ecosystem (npm). You use it to build servers, command-line tools, APIs and anything that needs JavaScript running on a machine rather than in a page.

JavaScript is the language; Node.js is one environment that runs it. In the browser the language comes with a DOM, events and window APIs — in Node those are replaced by the file system, network and process modules. Syntax, functions, arrays, promises and async/await are identical, so your JavaScript knowledge transfers directly.

Browser code is sandboxed: it cannot read your files or open arbitrary ports. Node code has full machine access, which is why it is used for servers and tools but also why you never run untrusted code in it. There is no document or window in Node — the equivalents are global, process and modules.

npm is JavaScript's package manager and public registry. package.json describes your project: name, entry point, dependencies with version ranges, and scripts such as npm run dev. Installing a package copies it into node_modules and records the exact intent in package-lock.json so every machine installs identical versions.

Express is a minimal web framework for Node: a few thousand lines that give you routing, middleware, request parsing and static files on top of the raw HTTP server. It is the most common starting point for REST APIs and the backbone of this tutorial's project chapters.

Both work. CommonJS (require/module.exports) is the classic Node format; ES modules (import/export) are the standard and activated in a package.json with "type": "module". Modern projects favour ESM for browser compatibility, but you will read both in existing code, so this course teaches each.

Middleware are functions that run between the incoming request and the final response, in order: body parsing, logging, authentication, rate limits, error handling. Each receives the request, response and next function and can respond itself or pass control along — Express's pipeline model in one sentence.

A JSON file is perfect for learning CRUD: no setup, readable data, easy to reset. The moment you need concurrent writes, querying or multiple users, move to a real database — MySQL/PostgreSQL for relational data or MongoDB for documents. The storage chapter isolates persistence behind one module so swapping it later is straightforward.

A REST API exposes resources over HTTP using verbs on URLs: GET /api/todos lists, POST creates, PUT or PATCH updates, DELETE removes, and everything answers with JSON plus correct status codes (200, 201, 400, 404, 500). It is stateless — each request carries its own authentication — which makes it easy to cache, scale and consume from any frontend.

Node apps are long-running processes, not static files: deploy them to a Node-friendly host (a VPS, Render, Railway or Fly.io), keep secrets in environment variables, terminate HTTPS at a reverse proxy or platform edge, and send logs somewhere durable. The final chapter covers the full checklist including health checks and graceful shutdown.