Skip to content

Instantly share code, notes, and snippets.

@19h
Created February 19, 2013 22:51
Show Gist options
  • Save 19h/4990953 to your computer and use it in GitHub Desktop.
Save 19h/4990953 to your computer and use it in GitHub Desktop.
Node.js — Clear Terminal / Console. Reset to initial state.
console.reset = function () {
return process.stdout.write('\033c');
}
@olvrb
Copy link

olvrb commented Aug 29, 2018

@DesignByOnyx's answer works on Ubuntu bash on Windows 10.

@tutlane
Copy link

tutlane commented Oct 11, 2018

Thanks @ghost. For me Ctrl + L worked to clear node.js console.

@anriDo
Copy link

anriDo commented Nov 25, 2018

work on MacOS Mojave

@silavsale
Copy link

Node 5 strict mode requires this, which is the same as jimmywarting's answer but it also resets the cursor:

process.stdout.write('\x1B[2J\x1B[0f');

Thanks, its work on windows 10

@mishhubc
Copy link

The combinations Ctrl + L reset the full log.

Ctrl + L to clear screen - https://unix.stackexchange.com/questions/104094/is-there-any-way-to-enable-ctrll-to-clear-screen-when-set-o-vi-is-set

thanks

@mybouhssina
Copy link

Thank you.
If anyone is wondering when/how to call the function, the following is working for me :

app.listen(process.env.PORT || 3000,function (){
  process.stdout.write('\033c'); 
}

since app.listen accepts a callback method, hope this helps someone ! :)

@aacassandra
Copy link

Thank you @TemaSM, its beautiful

@0Charliecat
Copy link

0Charliecat commented Mar 19, 2021

Works on macOS Big Sur 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment