JS Sketchbooksee JavaScript think ✏️
← back to the map
9

Node.js

The big question: “JS without the browser: the terminal, process & env, files, Node’s event loop — where Playwright lives”

but why do we need this?

Every Playwright test you will ever write runs as a Node.js program, not inside a browser tab — and so does its test runner, and the CI server that runs it at 3am. If you don’t know what changes when JavaScript leaves the browser (no DOM, no window — but new powers instead), the terminal output, the CI logs, and half of Playwright’s setup will feel like unexplained magic.

in plain words

Every lesson so far ran JavaScript inside a browser tab. Node.js is the exact same language, the exact same V8 engine (0.2) — just with the browser walls removed. No DOM, no window, nothing to click. In exchange it gets powers a browser deliberately withholds: reading and writing real files, talking to the operating system, running as a server.

You’ll work in the terminal properly for the first time: typing commands, reading a script’s output and its stack trace when it crashes, and understanding exit codes — the single number a finished script hands back that tells a CI server “I passed” or “I failed.”

This phase also revisits Phase 6’s event loop from Node’s side — same one-thread, non-blocking model, different backstage crew (libuv instead of the browser’s Web APIs) — and gives you process.argv and process.env: exactly how a real Playwright suite reads a BASE_URL or a secret without hard-coding it.

words you’ll own after this
Node.js

A program that runs JavaScript outside the browser — no DOM, no window; new powers instead (files, servers, the OS).

terminal / CLI

The text window where you type commands and read a script’s output — how every real test suite actually gets run.

REPL

A live JavaScript prompt in the terminal — type an expression, see its value immediately.

process.argv

The list of extra words typed after a command — how a script accepts input from whoever ran it.

process.env

A script’s environment variables — where secrets and settings like BASE_URL actually live in real test suites.

exit code

The single number a script hands back when it finishes: 0 means success, anything else means CI marks the run failed.

CI

Continuous Integration — the robot server that re-runs your whole suite on every code change and reads exit codes to decide green or red.

fs (file system)

Node’s toolbox for reading and writing real files — where test reports and screenshots actually go.

after this phase, you can…
  • Explain what changes (and what doesn’t) when JS runs outside the browser
  • Run a script from the terminal and read its output and stack trace
  • Read command-line arguments and environment variables in a script
  • Read and write a real file with Node’s fs module
this phase’s lab — see it move

✏️ This phase’s interactive lab is still being drawn — it arrives together with the phase’s lessons.

the lessons
  1. 9.1
    What is Node, really?

    V8 unbolted from the browser: document vanishes, the computer’s powers arrive.

  2. 9.2
    The terminal, properly

    pwd/cd/ls, stack traces read calmly — and exit codes, the number CI lives by.

  3. 9.3
    Modules in Node: CJS vs ESM

    require vs import, and the "type": "module" switch — read any Node file cold.

  4. 9.4
    process: argv, env & exit

    One suite, many targets: BASE_URL, secrets, and the startup guard pattern.

  5. 9.5
    The file system

    Real files at last: fs read/write, path.join, cwd vs the file’s home — where reports land.

  6. 9.6
    Node’s event loop & non-blocking I/O

    6.2 backstage: the libuv workshop — how one thread reads a hundred files.

  7. 9.7
    fetch without a browser

    The envelope leaves a terminal: JSON in, JSON out — your first API check.

  8. 9.8
    Checkpoint: environment setup

    Install Node for real, init a project, aim it with env, verify the exit code.