close
The Wayback Machine - https://web.archive.org/web/20240630062947/https://www.geeksforgeeks.org/node-js-console-clear-method/
Open In App

Node.js console.clear() Method

Last Updated : 13 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The console.clear() method is used to clear the stdout, when stdout is a TTY (Teletype) i.e. terminal it will attempt to clear the TTY. When stdout is not a TTY, this method does nothing.

The console.clear() will work differently across different operating systems and terminal types. For Linux operating systems, console.clear() operates like the clear shell command in terminal. On Windows, console.clear() will clear the current terminal viewport for the Node.js binary.

Syntax:

console.clear()

Parameters: This method does not accept any parameters.

Below programs illustrate the console.clear() method in Node.js:

In this example, first we write the node.js command in the terminal and start node.js and then write basic command
BERJAYA

After console.clear(), the terminal will cleared same like the clear command do in the terminal
BERJAYA

To exit Node.js terminal press Ctrl + C two times or use .exit command.

Example:




// Node.js program to demonstrate the  
// Buffer.clear() Method
  
// Both two lines will not display
// the result on screen
console.log("GeeksforGeeks");
console.log("A computer science portal");
  
// Clear the previous screen
console.clear();
  
// Display the content
console.log("Clear the console screen");


Output:
BERJAYA

Reference: https://nodejs.org/api/console.html#console_console_clear


Previous Article
Next Article

Similar Reads

HTML DOM console clear() Method
The console.clear() method in HTML is used to clear the console and writes some message "Console was cleared" on the console whenever it is executed. This method does not require any parameter. Syntax: console.clear()Example: The below program illustrates the console.clear() method in HTML: C/C++ Code <!DOCTYPE html> <html> <head>
1 min read
Difference between console.dir and console.log
Console Object: The Console object provides access to the browser's debugging console, which can be seen using F12 or ctrl+shift+j. Console object contains many methods, log() and dir() are most used among. The console.log() method prints out a toString representation of the object in the console to the user. Syntax: console.log(object) or console.
2 min read
Difference Between console.time and console.timeEnd in JavaScript
In JavaScript, console.time and console.timeEnd are powerful tools used for performance measurement. These methods allow developers to measure the time a block of code takes to execute, which is particularly useful for optimizing performance and debugging. Table of Content What is console. time?What is console.timeEnd?Difference Between console.tim
2 min read
Node.js console.dir() Method
The console.dir() method is used to get the list of object properties of a specified object. These object properties also have child objects, from which you can inspect for further information. Syntax: console.dir( object ) Parameters: This method accepts single parameter which holds the object element. Example 1: <!DOCTYPE html> <html>
1 min read
Node.js console.timeEnd() Method
The console.timeEnd() method is the console class of Node.js. This method stops a timer that was previously started by using console.time() method and display the result using stdout. Syntax: console.timeEnd( label ) Parameter: This method accepts a single parameter label that holds the string value. If the label is not passed i.e the value of the
2 min read
Node.js console.time() Method
The console.time() method is the console class of Node.js. It is used to starts a timer that is used to compute the time taken by a piece of code or function. The method console.timeEnd() is used to stop the timer and output the elapsed time in milliseconds to stdout. The timer can be accurate to the sub-millisecond. Syntax console.time( label ) Pa
3 min read
Node.js console.assert() Method
The console.assert() method is an inbuilt application programming interface of the console module which is used to assert value passed to it as a parameter, i.e. it checks whether the value is true or not, and prints an error message, if provided and failed to assert the value. Syntax: console.assert(value, messages) Parameters: This method has two
2 min read
Node.js console.count() Method
The console.count() method is an inbuilt application programming interface of the console module which is used to count label passed to it as a parameter, by maintaining an internal counter for that specific label. Syntax: console.count(label) Parameters: This method has one parameter as mentioned above and described below: label: It is an optional
2 min read
Node.js console.timeLog() Method
The console.timeLog() method is an inbuilt function in Nodejs that is used to display the time for each execution. This function is proved to be effective when used in a loop. Syntax: console.log([label][, ...data]) Parameters: This function accepts two or more parameters. Return Value: This method displays the time for the execution. Below example
1 min read
Node.js console.countReset() Method
The console.countReset() method is an inbuilt application programming interface of the console module which is used to reset the count for the specific label passed to it as a parameter. Syntax: console.countReset( label ); Parameters: This method has one parameter as mentioned above and described below: label: It is an optional parameter that spec
2 min read
three90RightbarBannerImg