javascript - 在 NodeJS 中不使用换行符进行日志记录
问题描述
如何在每次没有换行符的情况下记录此数据流?
websocket.on('message', (msg) => {
console.log(msg.content);
}
});
以上将导致:
> streamedContent-1
> streamedContent-2
> streamedContent-3..
我想要实现的是:
> streamedContent-n // this line getting updated on each refresh, no new line
解决方案
您可以在 Node 应用程序中使用 c++stdout
方法在运行时“编辑”一行。
process.stdout.clearLine()
process.stdout.write(`\r${msg.content}`);
推荐阅读
- python - 向图像添加色度噪声
- asp.net - 当 dbcontext 中有多个模型时,如何创建一个空模型以传递给插入更新视图?
- hp-uft - 如果检查失败,则从 UFT 检查点获取布尔值而不抛出错误
- php - Pass variable from header.php to functions.php
- javascript - Socket.io 客户端如何知道用户是否连接到通道
- angular - TypeError:您在流中提供了“未定义”
- internet-explorer - Kerberos 身份验证仅适用于 IE -> 私人浏览器
- react-native - 在 React Native 中从 Google Places Autocomplete 获取纬度和经度
- c# - 如何保护使用 iTextSharp 签名的 pdf 文件?
- android-studio - Error related to resources_ap after upgrading to Android Studio 3.4