A simple solution is not to print a newline (i.e. not to use console.log
).
- Use
process.stdout.write
lines without the EOL character to print. - Use the carriage return character (
\r
) to return to the beginning of the line. - Use
\e[K
to clear all characters from the cursor position to the end of the line.
Example:
process.stdout.write("000");
process.stdout.write("\n111");
process.stdout.write("\n222");
The output in this line will be:
000
111
222
However, if you do:
process.stdout.write("000");
process.stdout.write("\n111");
process.stdout.write("\n222");
process.stdout.write("\r\x1b[K")
process.stdout.write("333");
Output:
000
111
222\r\x1b[K
333
:
000
111
333