Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.Js on windows - How to clear console

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"); 
like image 845
Deeptechtons Avatar asked Jan 25 '12 17:01

Deeptechtons


People also ask

How do you clear the console in console?

Use console. clear() method. This method clears the console and displays console was cleared message. Use the short cut Ctrl + L to clear the console.

How do I clear my console clear?

clear() The console. clear() method clears the console if the console allows it. A graphical console, like those running on browsers, will allow it; a console displaying on the terminal, like the one running on Node, will not support it, and will have no effect (and no error).

How do you clear the console in react JS?

Console clear() The clear() method clears the console. The clear() method also write "Console was cleared" in the console.


2 Answers

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'); } 
like image 186
sanatgersappa Avatar answered Oct 01 '22 02:10

sanatgersappa


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

This also works on windows. Win7 at least.

like image 20
lfree Avatar answered Oct 01 '22 01:10

lfree