How to erase characters printed in console

There are functions available for process.stdout:

var i = 0;  // dots counter
setInterval(function() {
  process.stdout.clearLine();  // clear current text
  process.stdout.cursorTo(0);  // move cursor to beginning of line
  i = (i + 1) % 4;
  var dots = new Array(i + 1).join(".");
  process.stdout.write("Waiting" + dots);  // write text
}, 300);

It is possible to provide arguments to clearLine(direction, callback)

/**
 * -1 - to the left from cursor
 *  0 - the entire line // default
 *  1 - to the right from cursor
 */

Update Dec 13, 2015: although the above code works, it is no longer documented as part of process.stdin. It has moved to readline

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)