Node.Js on windows - How to clear console

This is for Linux mainly; but is also reported to work in Windows.

There is Ctrl + L in Gnome Terminal that clears the terminal. It can be used with Python, Node JS or any other REPL running in terminal. It has the same effect as clear command.


This clears the console on Windows and puts the cursor at 0,0:

var util = require('util');
util.print("\u001b[2J\u001b[0;0H");

or

process.stdout.write("\u001b[2J\u001b[0;0H");

process.stdout.write('\033c');

This also works on windows. Win7 at least.


console.log('\033[2J');

This works on linux. Not sure about windows.

You can "trick" the user using something like this:

var lines = process.stdout.getWindowSize()[1];
for(var i = 0; i < lines; i++) {
    console.log('\r\n');
}