Skip to content

Instantly share code, notes, and snippets.

@Ambratolm
Last active March 11, 2022 23:51
Show Gist options
  • Save Ambratolm/63d9c4e2622e92a4033fe854518eb421 to your computer and use it in GitHub Desktop.
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()`.
// 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