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.
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,clusterandchild_processfor multi-core scaling, and betweenreadFileand a stream for large files. - Recognise when a module-format change (
"type": "module") breaksrequireand how.cjsfixes 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
- Detail
- V8 outside the browser; one process, no thread per request
- Detail
- Only when I/O uses the standard library's synchronous methods (a long-running callback also blocks the event loop)
- Detail
- Blocking counterparts of I/O methods end in
Sync
async with no await- Detail
- Runs synchronously
- 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)
- Introduction to Node.jsnodejs.org (opens in a new tab)
- About Node.jsnodejs.org (opens in a new tab)
- Overview of Blocking vs Non-Blockingnodejs.org (opens in a new tab)
- async functiondeveloper.mozilla.org (opens in a new tab)
- Worker threadsnodejs.org (opens in a new tab)
- Clusternodejs.org (opens in a new tab)
- Command-line APInodejs.org (opens in a new tab)
- File systemnodejs.org (opens in a new tab)
- Modules: Packagesnodejs.org (opens in a new tab)
- 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