Open In App

Node.js writeStream.getColorDepth() Method

Last Updated : 06 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




// Node.js program to demonstrate the
// writeStream.getColorDepth() method
  
// 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 color depth
  // by using getColorDepth() API
  const col = WriteStream
      .getColorDepth(process.env);
  
  // 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("No of color supported is :-  ",
         0, 28, 1234, "localhost");


Output:

No of color supported is :- 24

Example 2: Filename: index.js




// Node.js program to demonstrate the
// writeStream.getColorDepth() method
  
// Creating and initializing a
// WriteStream object
let WriteStream = process.stdout;
  
// Getting color depth
// by using getColorDepth() API
const col = WriteStream.getColorDepth(process.env);
  
// Displaying the result
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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads