The writeStream.clearScreenDown() method is an inbuilt application programming interface of class WriteStream within tty module which is used to clear this write stream object from the current cursor down.
Syntax:
writeStream.clearScreenDown([callback])
Parameters: This method does not accept any parameter but it invokes a callback function.
Return Value: This method returns boolean value true if the write object is clear otherwise false.
Example 1: Filename: index.js
// Node.js program to demonstrate the // writeStream.clearScreenDown() 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;
// Clearing the write stream object
// by using clearScreenDown() API
const col = WriteStream.clearScreenDown();
// 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( "The line is clear :- " ,
0, 26, 1234, "localhost" );
|
Output:
The line is clear :- true
Example 2: Filename: index.js
// Node.js program to demonstrate the // writeStream.clearScreenDown() method // Creating and initializing a // WriteStream object let WriteStream = process.stdout; // Clearing the write stream object // by using clearScreenDown() API const col = WriteStream.clearScreenDown(); // Displaying the result console.log( "The write stream object"
+ " is clear :- " + col);
|
Run the index.js file using the following command:
node index.js
Output:
The write stream object is clear :- true
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_clearscreendown_callback