Last active
March 11, 2022 23:51
-
-
Save Ambratolm/63d9c4e2622e92a4033fe854518eb421 to your computer and use it in GitHub Desktop.
Clear the console in NodeJS. This adds the method to the console object. So, it can be called via `console.cls()`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method 1 | |
console.cls = function () { | |
process.stdout.write("\033c"); // or process.stdout.write("\x1Bc"); | |
}; | |
// Method 2 | |
console.cls = function () { | |
const readline = require("readline"); | |
console.log("\n".repeat(process.stdout.rows)); | |
readline.cursorTo(process.stdout, 0, 0); | |
readline.clearScreenDown(process.stdout); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment