Open In App

Node.js writeStream.columns Property

Improve
Improve
Like Article
Like
Save
Share
Report

The writeStream.columns property is an inbuilt application programming interface of class WriteStream within the module which is used to get the number of columns this write Stream object has.

Syntax:

const writeStream.columns

Return Value: This property returns the number of columns this write Stream object contains.

Example 1: Filename: index.js

Javascript




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


Output:

Number of Columns :- 182

Example 2: Filename: index.js

Javascript




// Node.js program to demonstrate the
// writeStream.columns property
 
// Creating and initializing a WriteStream object
let WriteStream = process.stdout;
 
// Getting number of columns
// by using columns API
const col = WriteStream.columns;
 
// Displaying the result
console.log("Number of Columns :- " + col);


Output:

Number of Columns :- 182

Run the index.js file using the following command:

node index.js

Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_columns



Last Updated : 11 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads