How to erase characters printed in console

Viewed 51265

I've been searching how to do it in other languages and I've found that I have to use the special character \b to remove the last character. (how-do-i-erase-printed-characters-in-a-console-applicationlinux)

This doesn't work for node.js in multiple calls to console.log ();

If I write a single log:

console.log ("abc\bd");

I get the result: abd

But if I write:

console.log ("abc");
console.log ("\bd");

I get the result:

abc
d

My goal is to print a waiting message like:

Waiting
Waiting.
Waiting..
Waiting...

and again:

Waiting
Waiting.
etc

all in the same line.

6 Answers

This works for me:

process.stdout.write('\033c');
process.stdout.write('Your text here');

Using a Carriage Return

The carriage return character places the cursor back at the beginning of the current line.

process.stdout.write("\r");

This solution worked for me — I only tested it with a single character.

Related