rimraf
A `rm -rf` util for nodejs
Rimraf is a Node.js utility for deleting files and entire folder trees in one operation. It is the cross-platform equivalent of the Unix command rm -rf, which removes everything inside a directory recursively without asking for confirmation. The name comes from that command. It is installed via npm and used in JavaScript projects wherever you need to wipe out a directory as part of a build, cleanup, or deployment script.
The library exists because Node.js itself did not always provide a built-in way to delete folders reliably across operating systems. Windows in particular causes problems when deleting files that are still open or locked by another process. Rimraf handles those cases with automatic retries and a fallback strategy that moves files to a temporary location before removing them, which works around Windows file locking issues.
The API is straightforward: call rimraf with a path (or a list of paths) and it returns a Promise that resolves when deletion is complete. A synchronous version is also available. Options let you delete only files matching a pattern, skip certain files with a filter function, or cancel the operation partway through using an AbortSignal.
The README includes a prominent safety warning: you must never pass input from untrusted users to this function. Because its purpose is permanent deletion, passing the wrong path can destroy important data. The responsibility for what paths are passed to it stays with the developer using it.
Version 4 and later default to the built-in Node.js removal API on modern Node versions, falling back to the older JavaScript implementations only when needed. The current version requires Node 20 or 22 and above.