API Reference

rimraf

The UNIX rm -rf equivalent for Node.js, with glob support, cross-platform behavior, and a promise API.

Official Documentation ↗
CompatibilityThis documentation covers version v6.1.4. Check the official docs for the latest API surface.

Installation

npmnpm install rimraf

Methods

rimraf removes files and directories recursively, handling Windows path semantics and long paths.

Key Features

  • Recursive removal with glob patterns
  • Promise, sync, and native implementations
  • Handles Windows long paths and read-only flags

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/isaacs/rimraf@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:12.100Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/isaacs/rimraf@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:12.100Z.

FAQ

Is rimraf faster than fs.rm?
On Node 14.14+ fs.rm with recursive and force covers most needs. rimraf remains useful for glob patterns, filters, and consistent cross-platform behavior.
Can I exclude files with a pattern?
Yes. Pass a filter function in options; rimraf calls it per path and skips entries for which it returns false.
Is deletion reversible?
No. rimraf permanently deletes files. Always resolve and validate the target path before calling it, especially when the path comes from user input.