0

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

1 Answer 1

1

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}`);
Sign up to request clarification or add additional context in comments.

3 Comments

That worked perfectly. How would you color or format stdout by the way, since console.log hides that complexity for you?
There is a node module for that it's called chalk i think.
process.stdout.write('\r' + chalk.red(msg.content));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.