Stephan K.
Stephan K.

Reputation: 15702

Logging without newline in NodeJS

How to log this stream of data without a newline each time?

websocket.on('message', (msg) => {
    console.log(msg.content);
  }
});

Above would result in:

> streamedContent-1
> streamedContent-2
> streamedContent-3..

What I want to achieve is:

> streamedContent-n // this line getting updated on each refresh, no new line

Upvotes: 0

Views: 398

Answers (1)

DedaDev
DedaDev

Reputation: 5249

You can use c++ stdout methods inside a Node app to "edit" a line in runtime.

process.stdout.clearLine()
process.stdout.write(`\r${msg.content}`);

Upvotes: 1

Related Questions