Node.js writeStream.getWindowSize() Method
Last Updated :
01 Sep, 2020
The writeStream.getWindowSize() method an inbuilt application programming interface of class WriteStream within tty module which is used to get the size of the TTY corresponding to this WriteStream object.
Syntax:
writeStream.getWindowSize()
Parameters: This method does not accept any parameter.
Return Value: This method returns array of type [numColumns, numRows] containing numColumns and numRows.
Example 1: Filename: index.js
var dgram = require( 'dgram' );
var client = dgram.createSocket( "udp4" );
var server = dgram.createSocket( "udp4" );
server.on( "message" , function (msg) {
let WriteStream = process.stdout;
const col = WriteStream.getWindowSize();
process.stdout.write(msg + col[0]);
process.exit();
})
.bind(1234, () => {
});
client.send( "number columns of writestream :- " , 0,
50, 1234, "localhost" );
|
Output:
number columns of writestream :- 182
Example 2: Filename: index.js
let WriteStream = process.stdout;
const col = WriteStream.getWindowSize();
console.log( "number rows of writestream :- " + col[1]);
|
Run the index.js file using the following command:
node index.js
Output:
number rows of writestream :- 14
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_getwindowsize
Share your thoughts in the comments
Please Login to comment...