Error handling with node.js streams

What’s the correct way to handle errors with streams? I already know there’s an ‘error’ event you can listen on, but I want to know some more details about arbitrarily complicated situations. For starters, what do you do when you want to do a simple pipe chain: input.pipe(transformA).pipe(transformB).pipe(transformC)… And how do you properly create one … Read more

How do I read the contents of a Node.js stream into a string variable?

I’m hacking on a Node program that uses smtp-protocol to capture SMTP emails and act on the mail data. The library provides the mail data as a stream, and I don’t know how to get that into a string. I’m currently writing it to stdout with stream.pipe(process.stdout, { end: false }), but as I said, … Read more