rimraf is a robust, cross-platform Node.js module that provides functionality akin to the `rm -rf` UNIX command for deep, recursive file and directory deletion. Currently at version 6.1.3, it is actively maintained with periodic major releases introducing significant changes, such as the shift from callbacks to Promises and the move away from default exports. A key differentiator is its specialized handling of common file system issues on Windows, such as `EBUSY` or `EMFILE` errors, through strategies like "move then remove" and exponential backoff, making it more reliable than simple native `fs.rm` alternatives in certain scenarios. It offers both synchronous and asynchronous APIs, as well as options to select native or JavaScript-based implementations. A critical aspect of its usage is the explicit warning against passing untrusted input due to its aggressive deletion capabilities, which can lead to system destruction or compromise if misused.
npm install rimrafVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic asynchronous usage of `rimraf` to create a temporary directory and file, then recursively delete the directory, verifying its removal.
Upgrade your Node.js environment to version 20 or 22+.
Change `import rimraf from 'rimraf'` to `import { rimraf } from 'rimraf'` or `const { rimraf } = require('rimraf')`.Refactor code to use `await rimraf(...)` or `.then()` syntax instead of passing a callback function as the last argument.
Ensure globbing is explicitly enabled if paths contain glob patterns, for example: `await rimraf('path/*.txt', { glob: true })`. If using the CLI, add the `--glob` flag.Always sanitize and validate any user-supplied paths. Restrict `rimraf` usage to known, safe, application-controlled paths.
When experiencing persistent deletion issues on Windows, consider adjusting `maxRetries` or providing a `tmp` path that is on the same physical device as the target.
Update your import statement to use named imports: `import { rimraf } from 'rimraf'`.Refactor your code to use the Promise-based API: `await rimraf(path)` or `rimraf(path).then(() => ...)`. Do not pass a callback as the last argument.
Ensure no other processes (IDEs, terminals, antivirus) are accessing the target path. On Windows, consider configuring `maxRetries` or providing a `tmp` path. If possible, defer deletion until the resource is released.
Ensure `rimraf` is installed as a `devDependency` (`npm install --save-dev rimraf`) and run it via `npm script` (e.g., `npm run clean`) or `npx rimraf`. For global use, install with `npm install -g rimraf` and verify `npm`'s global bin directory is in your PATH.
Add the `{ glob: true }` option to your `rimraf` call: `await rimraf('path/*.txt', { glob: true })`. If using the CLI, add the `--glob` flag.No dependency data recorded yet.