Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use console.table but to stderr?

I find that console.table() is good, in a few cases, for error messages. However, it doesn't print to stderr. How do I print console.table to stderr in Node.js?

like image 693
ma1234 Avatar asked Oct 21 '25 07:10

ma1234


1 Answers

In Node.js, one can instantiate a custom Console instance with a different writable stream than stdout using the console module, e.g.:

const { Console } = require("console");
const console = new Console(process.stderr);

This would have any method that typically uses stdout, including table(), use stderr instead.

like image 122
Dave Shifflett Avatar answered Oct 23 '25 21:10

Dave Shifflett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!