Rimraf implements aggressive recursive file and directory removal for Node.js, modeled on rm -rf. It ships CLI and programmatic APIs with platform-specific strategies for busy files on Windows.
Overview
Node developers call rimraf when build scripts, test harnesses, or installers must delete directory trees reliably across POSIX and Windows filesystems. Recent releases return promises instead of callbacks and accept arrays of paths in one invocation.
The implementation prefers native kernel helpers when available, falling back to move-then-delete sequences on Windows when exponential backoff cannot clear busy handles. Glob expansion requires explicit opt-in flags after behavioral changes in major versions.
Install via npm provides both module exports and a command-line interface. Documentation stresses that untrusted paths must never reach the API because the tool is designed for destructive removal.
Build pipelines and file-sync utilities depend on rimraf to clean artifacts, temporary directories, and outdated caches during automated workflows.
Key features
- Recursive directory deletion
- Cross-platform path handling
- Windows busy-file fallbacks
- Promise-based async API
- Batch path deletion support
- Optional glob integration
- CLI and library interfaces
- Native implementation when possible
Use cases
- Cleaning build output folders
- Test fixture teardown
- Node script temp directory wipes
- Cross-platform install uninstallers
- CI cache directory resets