I'm working with JavaScript/Node and have a Websocket with a server that is sending a constantly updating string. My goal is to log the string dynamically in the console, so if the sequence of strings from the stream is
[string1, string1, string2, string2, string2, string3]
, then rather than have the console show
string1
string1
string2
string2
string2
string3
I want the console to show
stringI
Where stringI
is constantly updating and I
is in {1,2,3}
Currently, I'm doing this with
process.stdout.clearLine(0)
process.stdout.cursorTo(0)
process.stdout.write(new_string)
But I run into issues when the string is greater than one line length in the console.
Does anyone know how I can dynamically overwrite a constantly updating string in the console? Thanks!