Mikuso Mikuso - 8 months ago 24
Node.js Question

How to test if an object is a Stream in NodeJS

I have a function which receives an object that could be a


I can easily test if the object is a Buffer like so:
if (x instanceof Buffer)

What's the best way to test if an object is a Stream? There doesn't appear to be a Stream base class in node - is there?

What should I look for?


The prototype you are looking for is the stream.Readable stream for readable streams, and stream.Writable for writable streams. They work in the same way as when you check for Buffer.