Lesson 6.1Lesson 20 of 24
Node.js implementation choices
Given a scenario and requirements, infer which Node.js implementation is a good solution.
Key points
- 1Node.js runs your JavaScript on one main thread. I/O is handed off, and its callbacks run later from the event loop.
- 2Anything synchronous and slow, such as readFileSync in a request handler or a heavy loop, stops every other request until it ends.
- 3Use a stream for large or endless data: it handles one chunk at a time, so memory stays flat. Prefer stream.pipeline, which forwards errors.
- 4EventEmitter calls its listeners synchronously, in the order they were added. An error event with no listener throws.
- 5process.nextTick runs before promise callbacks; setImmediate runs on the next loop turn. Move CPU-heavy work to
worker_threads.
What the exam guide checks here
Objective wording from the exam guide (English).
- 6.1.K1Node.js as a single-threaded event-driven runtime; non-blocking I/O
- 6.1.K2Streams, EventEmitter, and when to use callbacks, promises or streams
- 6.1.S1Choose the Node.js implementation that meets a requirement
Lock it in
Answer scenario questions on this topic. Every option comes with an explanation.
Practise 6.1 · 12 questions