Node.js Internals
The one language-specific module: the event loop, async evolution, streams, modules, CPU-bound concurrency, and V8 memory. Targets Node 24 LTS.
- chapters
- 6
- objectives
- 21
- core
- 12
- est. time
- 2h 18m
- 01 4.1 The event loop & async model ★ core
Single-threaded JS + libuv thread pool, the event-loop phases in order, microtasks vs macrotasks, and the nextTick/setImmediate/setTimeout ordering rules.
- 02 4.2 Async evolution & error handling ★ core
Callbacks → Promises → async/await, and the error-handling traps: unhandled rejections and floating promises.
- 03 4.3 Streams & buffers
The four stream types, backpressure (why pipe/pipeline handle it), buffers for binary data, and the must-handle 'error' event.
- 04 4.4 Modules & packages ★ core
CommonJS vs ES Modules (and the exports vs module.exports gotcha), plus npm/package.json: deps vs devDeps, semver, lockfiles.
- 05 4.5 Globals, events & CPU concurrency
process/global/Buffer, the EventEmitter pattern, and picking worker threads vs child processes vs cluster for CPU-bound work.
- 06 4.6 V8, memory & frameworks
V8 + GC basics and how memory leaks happen, Express/Fastify/NestJS at a concept level, debugging with --inspect, and the common Node gotchas.
Section assessment
Harder, multi-concept questions drawn from across the module. Aim for 75%.
- 01hard
INSIDE an fs.readFile callback, which fires first?
- 02hard
What is logged?
async function f(){ throw new Error('boom'); } try { f(); } catch (e) { console.log('caught'); } console.log('after'); - 03hard
CPU-heavy image processing that must not block the HTTP server, sharing memory with the main process, calls for:
- 04medium
What does this print?
console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')); process.nextTick(() => console.log('D')); console.log('E'); - 05medium
After each operation, Node drains which queue FIRST?
- 06medium
What actually runs Node's async I/O (fs, DNS, crypto) off the main thread?
- 07medium
A “floating promise” is dangerous because:
- 08medium
Backpressure is signalled when:
- 09medium
In CommonJS, reassigning `exports = {...}` (instead of `module.exports`) is a gotcha because:
- 10medium
cluster is mainly used to:
- 11medium
Common Node memory-leak sources:
- 12easy
A long synchronous for-loop in a request handler blocks all other requests.