Install + verify
From nodejs.org to a live terminal.
- Download the LTS build from
nodejs.org. - Installer bundles Node.js + NPM — both arrive together.
- Verify with
node -vandnpm -v. - “Command not found” → PATH issue; restart terminal or reinstall with Add to PATH checked.
REPL — the playground
Read, Evaluate, Print, Loop.
- Type
nodein the terminal; exit with.exitorCtrl+Ctwice. - Reads one line, evaluates via V8, prints the return value, loops back.
let x = 5printsundefined— declarations have no return value.- Good for experiments; bad for real projects (nothing persists).
File mode
The real workshop.
- Create a folder → open in VS Code → create
app.js. - Run with
node app.js— the whole file executes top to bottom. - No HTML, no
<script>tag, no browser needed. - Use the integrated terminal with
Ctrl+`to keep editor + runner in one place.
global vs window
Every runtime has a global object.
- Browser:
window— DOM,alert,localStorage. - Node.js:
global—setTimeout,setInterval,setImmediate,console,fetch. globalis provided by Node, not V8 — V8 itself knows nothing about it.- Node has no DOM, no
alert, noprompt.
top-level this + globalThis
The interview trap.
- In a Node file, top-level
thisismodule.exports— an empty{}, notglobal. - In a browser, top-level
thisiswindow. globalThis(ES2020) is the universal reference —windowin browsers,globalin Node.- Use
globalThiswhen you want isomorphic code; useglobalinside Node when you don’t care about portability.
Comments
Comments are disabled in this environment. Set
PUBLIC_GISCUS_REPO,PUBLIC_GISCUS_REPO_ID, andPUBLIC_GISCUS_CATEGORY_IDto enable.