JS Sketchbooksee JavaScript think ✏️
← back to phase 9

9.8 — Checkpoint: environment setup

Checkpoint — and a special one: it happens outside this app, on your real computer. You’ll install Node, create a project from nothing, write a script that reads the environment and writes a file, run it from the terminal, and verify the exit code — the complete life cycle of everything Phase 9 taught.

This exact workspace is what Playwright installs into. (On an iPad right now? The dress rehearsal below covers you — the real install can wait for a computer.)

watch it happen
// the mission (on a real computer):
// 1  install Node LTS → node --version
// 2  mkdir first-node && cd first-node
// 3  npm init -y      → package.json
// 4  create hello.js:

import { writeFileSync } from "node:fs";

const who = process.env.USER_NAME ?? "friend";
const line = `hello, ${who}!`;
console.log(line);
writeFileSync("hello.txt", line);

// 5  node hello.js
// 6  USER_NAME=Lijas node hello.js
// 7  cat hello.txt    → hello, Lijas!
// 8  echo $?          → 0

The mission has eight boxes, and every one uses a lesson you already own. Nothing new gets taught today — that’s what makes it a checkpoint: 9.1’s runtime, 9.2’s terminal, 8.2’s npm, 9.3’s switch, 9.4’s env, 9.5’s files, all assembled into one working environment.

the setup checklist☐ install Node LTS☐ make a project folder☐ npm init -y☐ write hello.js☐ run it (defaults)☐ run it (env aimed)☐ verify the file☐ verify exit code 0the one checkpoint that happens OUTSIDE this app: build a real Nodeworkspace, end to end
under the hood

The deeper story, with the real names for things — this part is what turns “I saw it” into “I can explain it.”

Troubleshooting the two classic snags: “node: command not found” right after installing usually means the terminal was already open — close and reopen it so it re-reads its PATH (the list of folders the shell searches for commands). “Cannot use import statement outside a module” means box three’s "type": "module" line is missing — 9.3 told you this error’s whole story in advance.

Windows note: the inline NAME=value command form is a Mac/Linux shell feature. PowerShell splits it: $env:USER_NAME="Lijas"; node hello.js — and reads the last exit code as $LASTEXITCODE instead of $?. Same machine, different dialect (9.2’s shells).

What you did NOT need today is worth noticing: no bundler, no framework, no config beyond one JSON line. A runtime, a folder, a file, a terminal — that’s the irreducible core of every Node project, including the grandest test suite you’ll ever maintain.

Job note: “set up a project from scratch” is a real interview task for automation roles — and you just rehearsed it end to end. In Phase 11, npm init playwright@latest will do a fancier version of boxes three-and-four for you; now you’ll know exactly what it scaffolded and why.

your turn

⌨️ the dress rehearsal

Before (or instead of, for now) the real terminal: stage the entire hello.js mission in the sandbox — env-driven greeting, model-disk write, honest exit code.

requirements:

  • Model the run: env as { USER_NAME: "Lijas" } and a model disk const disk = {} (9.5’s trick).
  • Write greet(env): build hello, NAME! with a template literal, where NAME is env.USER_NAME with the honest default "friend".
  • Run the mission: print greet({}) (the default run), then print greet(env), then store greet(env) on the disk under "hello.txt" and print what the disk holds there.
  • Finish like a good process: print the exit code — 0 if the disk’s "hello.txt" now holds a value, 1 otherwise (a real check, not a bare 0).

when you press RUN, the console must show exactly:

hello, friend!
hello, Lijas!
hello, Lijas!
0

✏️ Quick check 1

Fresh machine, Node just installed. Which command proves the install worked?

✏️ Quick check 2

hello.js reads process.env.USER_NAME ?? "friend". You run it with nothing set. What prints?

✏️ Quick check 3

The run succeeded. What does echo $? print?

teach it back

🗣️ Now teach it back

Brief a friend through the whole setup mission from memory: install and verify, project + init (+ which line you add by hand and why), the script’s moving parts, the two runs, and the two verifications at the end.

Write it as if your friend is sitting next to you. Saved to your journal — future-you will use these notes to teach others.

a few sentences, minimum — you’ve got this
to remember
The mission: Node LTS (verify: node --version) → mkdir + cd → npm init -y (+ add "type": "module" yourself) → hello.js (env + ?? + template + writeFileSync) → run plain, run aimed → cat the file, echo $? → 0.
Every box was a lesson: 9.1 runtime, 9.2 terminal & exit codes, 8.2 npm, 9.3 module switch, 9.4 env, 9.5 files. Checkpoints assemble; they don’t introduce.
This workspace is the exact substrate Playwright installs into (Phase 11). Classic snags: reopen the terminal after installing (PATH); “Cannot use import statement” = the missing "type": "module" line.
next: 10.1 Why software breaks →