Node.Js on windows - How to clear console

前端 未结 19 1423
迷失自我
迷失自我 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:07
    process.stdout.write('\033c');
    

    This also works on windows. Win7 at least.

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

    Haven't tested this on Windows but works on unix. The trick is in the child_process module. Check the documentation. You can save this code as a file and load it to the REPL every time you need it.

    var util = require('util');
    var exec = require('child_process').exec;
    
    function clear(){
        exec('clear', function(error, stdout, stderr){
            util.puts(stdout);
        });    
    }
    
    0 讨论(0)
  • 2020-12-02 09:11

    This is for Linux mainly but is also reported to work in Windows.

    There is Ctrl + L in Gnome Terminal that clears the terminal as such. It can be used with Python, Node JS or any Interpreter presumably that uses terminal. I tend to clear many times hence this is very handy. Instaed of doing clear in Gnome Terminal you can just do Ctrl + L, it has nothing to do with the REPL running.

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

    If you're using VSCode you can use CTRL + K. I know this is not a generic solution but may help some people.

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

    Just use CTRL + L on windows to clear the console.

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

    And to clear the console while in strict mode on Windows:

    'use strict';
    process.stdout.write('\x1Bc'); 
    
    0 讨论(0)
提交回复
热议问题