Node.js writeStream.getColorDepth() Method
Last Updated :
06 Sep, 2020
The writeStream.getColorDepth() method is an inbuilt application programming interface of class WriteStream within tty module which is used to determine what color the terminal supports.
Syntax:
const writeStream.getColorDepth([env])
Parameters: This method accepts object containing the environment variables as an argument.
Return Value: This method returns the number of colors supported by this terminal.
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
.getColorDepth(process.env);
process.stdout.write(msg + col);
process.exit();
})
.bind(1234, () => {
});
client.send( "No of color supported is :- " ,
0, 28, 1234, "localhost" );
|
Output:
No of color supported is :- 24
Example 2: Filename: index.js
let WriteStream = process.stdout;
const col = WriteStream.getColorDepth(process.env);
console.log( "No of color supported is :- " + col);
|
Run the index.js file using the following command:
node index.js
Output:
No of color supported is :- 24
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_getcolordepth_env
Share your thoughts in the comments
Please Login to comment...