Open In App

Node.js writeStream.clearLine() Method

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The writeStream.clearLine() is an inbuilt application programming interface of class WriteStream within the module which is used to clear the current line of this write stream object.

Syntax:

writeStream.clearLine(dir[, callback])

Parameters: This method takes the following argument as a parameter:

  • dir: Integer value defining the selection of a line. 
  • callback: Invoked once the operation completes. 

Return Value: This method returns the boolean value true if the write object line is clear otherwise false.

Example 1: Filename: index.js

Javascript




// Node.js program to demonstrate the
// writeStream.clearLine() method
 
// Importing dgram module
const dgram = require('dgram');
 
// Creating and initializing client
// and server socket
const client = dgram.createSocket("udp4");
const 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 line
    // by using clearLine() API
    const col = WriteStream.clearLine();
 
    // 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

Javascript




// Node.js program to demonstrate the
// writeStream.clearLine() method
 
// Creating and initializing a
// WriteStream object
let WriteStream = process.stdout;
 
// Clearing the line
// by using clearLine() API
const col = WriteStream.clearLine();
 
// Displaying the result
console.log("The line is clear :- " + col);


Run the index.js file using the following command:

node index.js

Output:

The line is clear :-  true

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads