🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Untitled Lesson

Total XP: 0|💻 backend XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Select an unlocked node to view details root

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

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.

Continue Learning