rimraf
rimraf is a Node.js implementation of the Unix rm -rf command, providing cross-platform recursive directory and file deletion. The package handles the complexit…
Installation
npm install rimraf
yarn add rimraf
pnpm add rimraf
Import
import { rimraf } from 'rimraf';Quick Example
import { rimraf } from 'rimraf';
await rimraf('dist');
await rimraf(['tmp', 'cache', '.parcel-cache']);
// In package.json scripts:
// "clean": "rimraf dist node_modules/.cache"About rimraf
rimraf is a Node.js implementation of the Unix rm -rf command, providing cross-platform recursive directory and file deletion. The package handles the complexities of deleting directory trees on different operating systems — particularly Windows, where files can be locked by other processes, paths can exceed MAX_PATH limits, and junction points need special handling. rimraf retries failed deletions with configurable backoff for handling temporary file locks, supports glob patterns for selecting files to delete, and provides both sync and async APIs. Version 5+ of rimraf uses Node.js's native fs.rm with recursive option when available, falling back to manual traversal for older Node.js versions. The package also provides a CLI interface (npx rimraf dist node_modules) for use in npm scripts. rimraf is one of the most commonly used packages in the npm ecosystem, appearing in thousands of projects' clean and prebuild scripts for removing build output directories, cache directories, and node_modules. The name stands for 'remove recursively, I'm forced' or simply references the rm -rf Unix command. While Node.js 14.14+ includes fs.rm with recursive support, rimraf's Windows handling and retry logic make it more reliable for cross-platform use.
Quick Facts
| Package | rimraf |
| Category | File System |
| Weekly Downloads | 30M+ |
| License | ISC |
| Install | npm install rimraf |
Related Packages
fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system …
mkdirp is a Node.js utility that recursively creates directories, equivalent to mkdir -p in Unix. Gi…
glob is a library for matching files using glob patterns — the wildcard syntax familiar from shell c…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.