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:
console.log("GeeksforGeeks");
console.log("A computer science portal");
console.clear();
console.log("Clear the console screen");
|
Output:

Reference: https://nodejs.org/api/console.html#console_console_clear
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
13 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...