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

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

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:

Reference: https://nodejs.org/api/console.html#console_console_clear
Recommended Posts:
- Node.js | NPM (Node Package Manager)
- How to resolve 'node' is not recognized as an internal or external command error after installing Node.js ?
- Node | URLSearchParams.has() Method
- Node.js | crypto.createHash() Method
- Node.js writeStream.clearLine() Method
- Node.js | fs.link() Method
- Run Python script from Node.js using child process spawn() method
- Node.js v8.Serializer.writeDouble() Method
- Node.js v8.Serializer.writeRawBytes() Method
- Node.js v8.Deserializer.readHeader() Method
- Node.js v8.Deserializer.readValue() Method
- Node.js | Buffer.readUInt16LE() Method
- Node.js | fs.mkdir() Method
- HTML | DOM Node isSupported() Method
- Node.js | vm.runInThisContext() Method
- Node.js | Buffer.readUInt32BE() Method
- Node.js util.debuglog() Method
- Node.js | fs.mkdtempSync() Method
- Node.js | process.chdir() Method
- Node.js | Buffer.allocUnsafe() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

