Skip to content
Related Articles

Related Articles

Improve Article

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






// Node.js program to demonstrate the
// writeStream..getWindowSize()  API
  
// Importing dgram module
var dgram = require('dgram');
  
// Creating and initializing client
// and server socket
var client = dgram.createSocket("udp4");
var server = dgram.createSocket("udp4");
  
// Handling the message event
server.on("message", function (msg) {
  
  // Creating and initializing a
  // WriteStream object
  let WriteStream = process.stdout;
  
  // Getting window size of this write stream
  // object by using .getWindowSize() API
  const col = WriteStream.getWindowSize();
  
  // Displaying the result
  process.stdout.write(msg + col[0]);
  
  // Exiting process
  process.exit();
})// Binding server with port
.bind(1234, () => {
});
  
// Client sending message to server
client.send("number columns of writestream :-  ", 0,
50, 1234, "localhost");

Output:

number columns of writestream :-  182

Example 2: Filename: index.js




// Node.js program to demonstrate the
// writeStream..getWindowSize()  API
  
// Creating and initializing a WriteStream object
let WriteStream = process.stdout;
  
// Getting window size of this write stream
// object by using .getWindowSize() method
const col = WriteStream.getWindowSize();
  
// Displaying the result
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




My Personal Notes arrow_drop_up
Recommended Articles
Page :