Check if a stream is process.stdout

385 views Asked by At

Is there an elegant way to determine if a stream is process.stdout

I am working with streams and will like to end the stream, but found out that if the stream is process.stdout an error is thrown because process.stdout is a special stream that cannot be closed. So want to end all streams except it's process.stdout

I tried using a try and catch, but the process.stdout error ends the node process, ignoring the try and catch.

1

There are 1 answers

6
T.J. Crowder On BEST ANSWER

Perhaps this is naive of me, but I'd think you can just check with !==:

if (theStream !== process.stdout) {
    theStream.end();
}

Streams are objects, and there's only one process.stdout, so...