Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How wide is the node.js console?

Tags:

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.

like image 426
agent-j Avatar asked Jun 08 '12 21:06

agent-j


People also ask

What is the Nodejs console?

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.

Does node have a console?

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.

Is node js still relevant in 2021?

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.

How do I open node JS console?

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.


2 Answers

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

like image 50
Mike Kellogg Avatar answered Nov 06 '22 05:11

Mike Kellogg


if (process.stdout.isTTY) {   console.log("The console size is:", process.stdout.getWindowSize()); } else {   console.log("stdout is not a console"); }  
like image 21
Someone Avatar answered Nov 06 '22 05:11

Someone