Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
What is the primary architectural advantage of using Streams to process a large 5GB file instead of using the standard `fs.readFile()` method?
💻 Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Streams and Buffers pipeline. Include the setup and basic execution steps.
You are reviewing a Node Streams and Buffers pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Ignoring backpressure by writing to a Writable stream manually without checking the return value of .write()
// Wrong: ignores backpressure, can balloon memory
for (const chunk of chunks) {
writeStream.write(chunk); // return value ignored
}
// Correct: let pipe() manage backpressure for you
readStream.pipe(writeStream);The Solution //
stream.write(chunk) returns false when the internal buffer is full, meaning you're producing data faster than the destination can consume it — if you keep calling .write() anyway (e.g. in a tight loop reading from a fast source into a slow destination), memory balloons as Node buffers everything internally. Either use .pipe() (which handles backpressure automatically) or manually pause the source and wait for the 'drain' event before writing more.
The Error //
Not handling the 'error' event on a stream, causing an unhandled exception and process crash
// Wrong: an ENOENT/network error here can crash the whole process
fs.createReadStream('maybe-missing.mp4').pipe(res);
// Correct: pipeline() forwards errors and cleans up automatically
const { pipeline } = require('stream');
pipeline(fs.createReadStream('maybe-missing.mp4'), res, (err) => {
if (err) console.error('Stream failed:', err);
});The Solution //
Streams emit errors asynchronously via an 'error' event rather than throwing synchronously — if nothing is listening for it (especially on a Readable stream reading from disk or network), Node treats it as an uncaught exception and can crash the entire process. Always attach an .on('error', handler) to every stream in a pipeline, or use stream.pipeline() which handles error propagation and cleanup for you.