console.log(process.env.COLUMNS)
Yields undefined
, although,
$ echo $COLUMNS
Outputs as expected:
78
I have been trying running Node like this env node myprog.js
, still undefined
. What's wrong with me or any other way to know the width of terminal? (For nice formatting of some output data).
console.log('Terminal size: ' + process.stdout.columns + 'x' + process.stdout.rows);
And the output looks like e.g. "Terminal size: 80x24". There is also an event if the console size changes.
It's explained under tty in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With