Node.Js on windows - How to clear console

前端 未结 19 1426
迷失自我
迷失自我 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:14

    This code works fine on my node.js server console Windows 7.

    process.stdout.write("\u001b[0J\u001b[1J\u001b[2J\u001b[0;0H\u001b[0;0W");

    0 讨论(0)
  • 2020-12-02 09:15

    This clears the console on Windows and puts the cursor at 0,0:

    var util = require('util');
    util.print("\u001b[2J\u001b[0;0H");
    

    or

    process.stdout.write("\u001b[2J\u001b[0;0H");
    
    0 讨论(0)
  • 2020-12-02 09:16
    console.log('\033[2J');
    

    This works on linux. Not sure about windows.

    You can "trick" the user using something like this:

    var lines = process.stdout.getWindowSize()[1];
    for(var i = 0; i < lines; i++) {
        console.log('\r\n');
    }
    
    0 讨论(0)
  • 2020-12-02 09:16

    i am using a windows CMD and this worked for me

    console.clear();
    
    0 讨论(0)
  • 2020-12-02 09:19

    Starting from Node.JS v8.3.0 you can use method clear:

    console.clear()
    
    0 讨论(0)
  • 2020-12-02 09:20

    I couldn't get any of the above to work. I'm using nodemon for development and found this the easiest way to clear the console:

      console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    

    It just scrolls the console several lines so you get a clear screen for subsequent console.log commands.

    Hope it helps someone.

    0 讨论(0)
提交回复
热议问题