Node.Js on windows – How to clear console?

Node.Js on windows – How to clear console?

Asked on October 26, 2018 in Windows.
Add Comment


  • 7 Answer(s)

      Use this code:

    console.log('\033[2J');
    

      It work greatly on linux but not sure about windows

      One possible way is “trick” the user by using something like this:

    var lines = process.stdout.getWindowSize()[1];
    for(var i = 0; i < lines; i++)
    {
      console.log('\r\n');
    }
    
    Answered on October 26, 2018.
    Add Comment

    This code works on window:

    process.stdout.write('\033c');
    
    

     

    Answered on October 26, 2018.
    Add Comment

    This code is used to 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");
    
    
    Answered on October 26, 2018.
    Add Comment

    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 manager.Windows Cmd prompt is being currently used for running nodejs apps.

    1. cls clears the command window or errors in command prompt. Is there a equivalent for node.js ? console.clear does not exist ;( or does it in some other form?
    2. I created a server through this code below
      var http = require("http");
      http.createServer(function (request, response) {
          response.writeHead(200, {
              "Content-Type": "text/html"
          });
          response.write("Hello World");
          console.log("welcome world")response.end();
      }).listen(9000, "127.0.0.1");
      

    i changed the code to below and refreshed the browser to find that content type does not change, how do i get to see the changes?

    var http = require("http");
    http.createServer(function(request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.write("Hello World");
      console.log("welcome world")
      response.end();
    }).listen(9000,"127.0.0.1");
    
    Answered on January 19, 2019.
    Add Comment
    1
    console.log('\033[2J');

    It work greatly on linux but not sure about windows

    One possible way is “trick” the user by using something like this:

    1
    2
    3
    4
    5
    var lines = process.stdout.getWindowSize()[1];
    for(var i = 0; i < lines; i++)
    {
      console.log('\r\n');
    }
    Answered on January 19, 2019.
    Add Comment
    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');
    }
    Answered on February 17, 2019.
    Add Comment
    process.stdout.write('\033c');

    This also works on windows. Win7 at least

    Answered on February 17, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.