Node.js writeStream.isTTY Property
Last Updated :
11 Apr, 2023
The writeStream.isTTY property is an inbuilt application programming interface of class WriteStream within ‘tty’ module which is used to check if the write Stream object is an instance of tty or not. It will always return true for tty, writeStream.
Syntax:
const writeStream.isTTY
Return Value: This property returns true if the write Stream object is an instance of tty.
Example 1: Filename: index.js
Javascript
const dgram = require( 'dgram' );
let client = dgram.createSocket( "udp4" );
let server = dgram.createSocket( "udp4" );
server.on( "message" , function (msg) {
let WriteStream = process.stdout;
const status = WriteStream.isTTY;
if (status)
process.stdout.write(msg
+ "an instant of TTY" + "\n" );
else
process.stdout.write(msg
+ "not an instant of TTY" + "\n" );
process.exit();
})
.bind(1234, () => {
});
client.send( "It is " , 0, 7, 1234, "localhost" );
|
Output:
It is an instant of TTY
Example 2: Filename: index.js
Javascript
let WriteStream = process.stdout;
const status = WriteStream.isTTY;
if (status)
console.log( "It is an instant of TTY" );
else
console.log( "It is not an instant of TTY" );
|
Output:
It is an instant of TTY
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_istty
Share your thoughts in the comments
Please Login to comment...