单行控制台输出作为变量而不是一个console.log每个变量值



node.js中是否有手段将控制台显示到单行中的计数器,而不是console.log每行?

,例如

let x = 1
while (x <= 10) {
  console.log(`The value assigned to 'x' is now: ${x}`);
  x++;
  }

打印10行的x = 1至10。

是否有可能拥有一条线,该线路作为x值增量保持静态?作为用例,如果x的值增加到100万,则控制台将显示一行,直到x为1000000。

这对一行有用:

const process = require('process');
let x = 1;
process.stdout.write(`The count is now at: ${x}`);
const counter = () => {
  process.stdout.clearLine();
  process.stdout.cursorTo(0);
  x++;
  process.stdout.write(`The count is now at: ${x}`);
  if(x >= 10) {
    clearInterval(cycle);
    process.stdout.write('n');
  }
};
const cycle = setInterval(counter, 1000);

...然后是:https://github.com/sindresorhus/log-update

相关内容

最新更新