【问题标题】:Nodejs, how to display and update text on the same line, like a running clock or download speed?Nodejs,如何在同一行显示和更新文本,例如运行时钟或下载速度?
【发布时间】:2019-07-17 11:08:08
【问题描述】:

在 nodejs 中,如何在同一行显示和更新文本,例如运行时钟或当前下载速度?

【问题讨论】:

    标签: javascript node.js terminal console


    【解决方案1】:
    'use strict';
    
    const rl = require('readline');
    
    function clearLine() {
      rl.cursorTo(process.stdout, 0);
      rl.clearLine(process.stdout, 0);
    }
    
    setInterval(() => {
      clearLine();
      process.stdout.write(new Date().toString());
    }, 1000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 2012-02-22
      相关资源
      最近更新 更多