In node.js, how do I get the current width of the console window and/or buffer?
The analog in .net is Console.BufferWidth and/or Console.WindowWidth.
I want to exercise more control over my line wrapping.
Node. js console is a global object and is used to print different levels of messages to stdout and stderr. There are built-in methods to be used for printing informational, warning, and error messages.
The node:console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: A Console class with methods such as console.
The short answer is “NO.” The long answer is, “NO, it's not dead, and it probably will never die.” Node. js is just as relevant to coding in 2021 and beyond, even if the hype around it has stabilized slightly.
js/JavaScript code. To launch the REPL (Node shell), open command prompt (in Windows) or terminal (in Mac or UNIX/Linux) and type node as shown below. It will change the prompt to > in Windows and MAC. You can now test pretty much any Node.
Looks like the current best way is this property:
process.stdout.columns
And for height (rows):
process.stdout.rows
Also note that there is a "resize" event, which might come in handy:
process.stdout.on('resize', function() { console.log('screen size has changed!'); console.log(process.stdout.columns + 'x' + process.stdout.rows); });
Documentation here: http://nodejs.org/api/tty.html#tty_tty
if (process.stdout.isTTY) { console.log("The console size is:", process.stdout.getWindowSize()); } else { console.log("stdout is not a console"); }
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