Skip to content

Instantly share code, notes, and snippets.

@RyanNorooz
Forked from timneutkens/index.js
Last active January 4, 2022 01:29
Show Gist options
  • Save RyanNorooz/62421930de4deb52bb122f6e42eb0b0c to your computer and use it in GitHub Desktop.
Save RyanNorooz/62421930de4deb52bb122f6e42eb0b0c to your computer and use it in GitHub Desktop.
Clear console/terminal in node.js the right way (preserve terminal history)
const readline = require('readline')
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
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