Server Side JavaScript8% of the exam

Node.js runtime: non-blocking I/O and scaling

How Node.js serves many connections from one thread, why synchronous and CPU-bound code stalls every request, and how to pick streams, worker_threads, cluster or child_process for large files, heavy computation and multi-core scaling.

Official exam objective
Given a scenario and requirements, infer which Node.js implementation is a good solution.

~7 min read · 6 practice questions ·

What the exam expects

  • Describe the Node.js runtime model (V8 outside the browser, one process, non-blocking I/O) and say which workloads it suits.
  • Predict the output order when synchronous (*Sync) and callback-based file reads are mixed.
  • Keep a server responsive when one request does heavy CPU work, and reject fixes that only look asynchronous.
  • Choose between worker_threads, cluster and child_process for multi-core scaling, and between readFile and a stream for large files.
  • Recognise when a module-format change ("type": "module") breaks require and how .cjs fixes it.

Key terms: event loop (the single thread that runs your JavaScript callbacks); blocking (more JavaScript must wait until a non-JavaScript operation finishes); Worker Pool (libuv's threadpool for expensive tasks such as file I/O); worker thread (a Worker running JavaScript in parallel inside the same process); cluster (several Node.js processes sharing one server port).

Key facts

Runtime
Detail
V8 outside the browser; one process, no thread per request
When I/O blocks the process
Detail
Only when I/O uses the standard library's synchronous methods (a long-running callback also blocks the event loop)
Blocking method names
Detail
Blocking counterparts of I/O methods end in Sync
async with no await
Detail
Runs synchronously
Workers fit
Detail
CPU-intensive JavaScript; not much help for I/O-intensive work
cluster
Detail
Child processes that share server ports; round-robin by default except on Windows
UV_THREADPOOL_SIZE
Detail
Sizes libuv's threadpool, default 4
fs.readFile() memory
Detail
Buffers the entire file; prefer fs.createReadStream()
.cjs / .mjs
Detail
Always CommonJS / always ES module, regardless of type
Sources for this section (9)
  • Why can one Node.js process handle thousands of concurrent connections?
  • When does a `readFile()` callback run relative to code written after it?
  • When should you choose `worker_threads` over `cluster`?
  • Which pattern reads a multi-gigabyte file one line at a time?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the JavaScript Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 24 lessons of the JavaScript Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (6 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the JavaScript Developer exam