clear

A tiny Node.js module that clears the terminal screen using ANSI escape codes.

Library
npm
v0.1.0
114stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
26/100Needs Attention
Development Activity0
Maintenance0
Community32
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
50/100Fair
Architecture35
Code Quality45
Innovation25
Learning Curve95

clear is a minimal Node.js utility that clears the terminal screen from within a running program, the same way the shell clear command does. It writes the ANSI escape sequences for erasing the display and resetting cursor position, with an opts.fullClear flag to just move the cursor back to 0,0 without wiping existing output — useful for CLI tools that redraw the same region repeatedly.

What You Get

  • A single clear() function export that clears the terminal when called
  • An opts.fullClear boolean to choose between a full screen erase and a cursor-only reset
  • Zero runtime dependencies and a tiny (13-line) implementation
  • Works anywhere Node.js writes to process.stdout, independent of shell or OS

Common Use Cases

  • Clearing the screen between redraws in interactive CLI tools (progress bars, menus, dashboards)
  • Resetting terminal output before printing a fresh render of a status screen
  • Building simple terminal games or REPL-style tools that repaint the same screen area
  • Cleaning up console output at the start of a long-running CLI command

Under The Hood

Architecture clear is a single function in index.js that writes two ANSI escape sequences to process.stdout — one to erase the visible screen (\x1b[2J) and one to move the cursor to the top-left (\x1b[0f) — gated by an opts.fullClear flag that skips the erase step when set to false. Tech Stack It’s plain CommonJS JavaScript with no runtime dependencies, no build step, and no TypeScript types; the only requirement is a Node.js process.stdout stream connected to an ANSI-capable terminal. Code Quality The implementation is intentionally tiny with basic assert-based argument validation for opts and opts.fullClear, and there is no accompanying test suite given the module’s minimal surface area. API Design The single-function, single-option API is about as low-ceremony as a Node.js utility can get — require('clear'); clear(); — with no further concepts to learn beyond the one boolean flag.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search