简体   繁体   English

在 NodeJS 中不使用换行符进行日志记录

[英]Logging without newline in NodeJS

How to log this stream of data without a newline each time?如何在每次没有换行符的情况下记录此 stream 数据?

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

You can use c++ stdout methods inside a Node app to "edit" a line in runtime.您可以在 Node 应用程序中使用 c++ stdout方法在运行时“编辑”一行。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM