-
-
Save 19h/4990953 to your computer and use it in GitHub Desktop.
console.reset = function () { | |
return process.stdout.write('\033c'); | |
} |
don't work in strict mode on node v6
But write("\x1B[2J")
did
Thanks, it worked for me. don't forget to call the function
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');
@DesignByOnyx Thanks man!
Sweet! Thanks.
Strict mode + Node.js all supported platforms:
'use strict';
process.stdout.write('\x1Bc');
// or
console.log('\x1Bc');
or you could use the key combinations Ctrl + L
Thank you @DesignByOnyx
process.stdout.write('\x1B[2J\x1B[0f\u001b[0;0H');
what is the '\x1Bc' it look like a regular expression, why does it clear the console
@TheRealCasadaro It's an ANSI Escape Sequence which clears the screen and buffer for the terminal output. It basically becomes <ESC>c
which is the VT100 escape code for resetting the terminal.
http://www.termsys.demon.co.uk/vtansi.htm
https://en.wikipedia.org/wiki/ANSI_escape_code
The combinations Ctrl + L
reset the full log.
thank you it works like a charm
Thank you @DesignByOnyx!
Works on my debian 8 :D
Works perfectly on Windows 10 Node.js v8.9.1.
Thanks.
Thank you @DesignByOnyx
It works on Windows 10 Node.js v.8.5
@SLeonescu Wow, thanks, that's so easy!
Thank you @TemaSM
or via package.json
:
"scripts": {
+ "cls_opt1": "clear",
+ "cls_opt2": "node -e \"process.stdout.write('\\033c')\""
}
console.clear()
does the trick without having to use keyboard shortcuts every time you run your js files
The below is better, because it clears also scroll-back buffer
process.stdout.write('\033c\033[3J');
http://man7.org/linux/man-pages/man4/console_codes.4.html
ESC [ 3 J: erase whole display including scroll-back buffer (since Linux 3.0).
@DesignByOnyx's answer works on Ubuntu bash on Windows 10.
work on MacOS Mojave
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
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
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 ! :)
Thank you @TemaSM, its beautiful
Works on macOS Big Sur 😸
work on ubuntu, node v5.10.0
P/s: or just simply
console.log('\033c')
will do