相关疑难解决方法(0)

Node.js console.log - 是否可以更新一行而不是创建新行?

我的node.js应用程序有很多控制台日志,这对我来说很重要(它是一个非常大的应用程序,因此运行了很长时间,我需要知道事情仍在进行中)但我最终会有数千行控制台日志.

是否可能以某种方式console.update擦除/替换控制台线而不是创建新线?

javascript node.js

63
推荐指数
8
解决办法
3万
查看次数

process.stdout 在 childProcess 中没有函数“clearLine”

在“Main.js”中,我使用spawn创建一个child_process。我想从“work.js”获取数据,但它显示错误

\n\n
TypeError: out.clearLine is not a function\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果node work.js在终端中使用\xef\xbc\x8cit 工作正常\xe3\x80\x82\n看起来 process.stdout 在 childProcess 中没有函数“clearLine”。

\n\n

main.js

\n\n
var spawn = require(\'child_process\').spawn;\nvar child = spawn(\'node\',[\'work.js\']);\nchild.stdout.on(\'data\', function (data) {\n    console.log(\'data:\',data.toString());\n})\nchild.stderr.on(\'data\', function (data) {\n    console.log("stderr:", data.toString());\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

工作.js

\n\n
var out = process.stdout;\nvar idx = 0;\nvar id = setInterval(()=>{\n    idx++;\n    out.clearLine();\n    out.cursorTo(0);\n    out.write(\'workTime:\' + idx);\n    if(idx>3){\n        clearInterval(id);  \n        console.log();\n        console.log(\'end\')\n    }\n},100)\n
Run Code Online (Sandbox Code Playgroud)\n\n

这只是一个演示,我无法更改 work.js。我该如何解决 main.js 中的问题,谢谢

\n

javascript node.js

6
推荐指数
1
解决办法
4317
查看次数

Nodejs中的cursorTo有什么用?

我读了一个nodejs的文件,遇到了一个方法cursorTo,我不明白它。请有人解释一下。

function refreshConsole () {
    if (Settings.properties.preventMessageFlicker) {
        readline.cursorTo(process.stdout, 0, 0);
    } else {
        process.stdout.write('\033c');
    }
}
Run Code Online (Sandbox Code Playgroud)

node.js

2
推荐指数
1
解决办法
2716
查看次数

清除NodeJS流中的所有行

process.stdout.clearLine()删除最新行.如何删除所有行stdout

var out = process.stdout;
out.write("1\n"); // prints `1` and new line
out.write("2");   // prints `2`

setTimeout(function () {
    process.stdout.clearLine(); // clears the latest line (`2`)
    out.cursorTo(0);            // moves the cursor at the beginning of line
    out.write("3");             // prints `3`
    out.write("\n4");           // prints new line and `4`
    console.log();
}, 1000);
Run Code Online (Sandbox Code Playgroud)

输出是:

1
3
4
Run Code Online (Sandbox Code Playgroud)

我想删除所有行stdout而不是最新行,因此输出将是:

3
4
Run Code Online (Sandbox Code Playgroud)

stream node.js

1
推荐指数
1
解决办法
3163
查看次数

标签 统计

node.js ×4

javascript ×2

stream ×1