Node.Js on windows - How to clear console

前端 未结 19 1569
迷失自我
迷失自我 2020-12-02 08:51

Being totally new into node.js environment and philosophy i would like answers to few questions. I had downloaded the node.js for windows installer and also node package man

19条回答
  •  感情败类
    2020-12-02 09:25

    In my case I did it to loop for ever and show in the console a number ever in a single line:

    class Status {
    
      private numberOfMessagesInTheQueue: number;
      private queueName: string;
    
      public constructor() {
        this.queueName = "Test Queue";
        this.numberOfMessagesInTheQueue = 0;
        this.main();
      }
    
      private async main(): Promise {    
        while(true) {
          this.numberOfMessagesInTheQueue++;
          await new Promise((resolve) => {
            setTimeout(_ => resolve(this.showResults(this.numberOfMessagesInTheQueue)), 1500);
          });
        }
      }
    
      private showResults(numberOfMessagesInTheQuee: number): void {
        console.clear();
        console.log(`Number of messages in the queue ${this.queueName}: ${numberOfMessagesInTheQuee}.`)
      }
    }
    
    export default new Status();
    

    When you run this code you will see the same message "Number of messages in the queue Test Queue: 1." and the number changing (1..2..3, etc).

提交回复
热议问题