Tuesday 2 October 2018

node.js: console.clear(): Clear the messages on terminal

‘console.clear()’ method clears the messages on terminal.

HelloWorld.js

console.log("Hello World");
console.log("Going to sleep for 2 seconds");

/* Wait for 2 seconds */
var seconds = 2;
var waitTill = new Date(new Date().getTime() + seconds * 1000);
while(waitTill > new Date()){}

console.clear();

console.log("Cleared old messages");

Note
When stdout is not a TTY, this method does nothing.


Previous                                                 Next                                                 Home

No comments:

Post a Comment