Skip to Content
APIrm

rm

Remove files and directories. Supports recursive removal with optional concurrency (Rush-FS extension) for faster deletion of large trees.

Basic usage

import { rm } from '@rush-fs/core' // Remove a file await rm('./tmp.txt') // Remove a directory recursively await rm('./temp-dir', { recursive: true }) // Force (ignore errors when path does not exist) + retries await rm('./maybe-missing', { recursive: true, force: true, maxRetries: 3 }) // Recursive with concurrency (Rush-FS: faster for large trees) await rm('./large-tree', { recursive: true, force: true, concurrency: 4 })

Methods

rm(path, options?)

Async. Returns Promise<void>.

ArgumentTypeDescription
pathstringPath to file or directory.
optionsobjectOptional. See below.

Options:

OptionTypeDefaultDescription
forcebooleanfalseIf true, ignore ENOENT (path not found).
maxRetriesnumber0Retry on transient errors (e.g. Windows locking).
recursivebooleanfalseIf true, remove directory and its contents.
retryDelaynumber100Delay in ms between retries.
concurrencynumber1(Rush-FS) Max concurrent delete operations in recursive mode.

rmSync(path, options?)

Sync. Same arguments; throws on error.

Performance

  • Recursive: Rush-FS can be ~1.75× faster than Node.js for large trees when using concurrency (e.g. 2000 files with 4 threads in benchmarks). Higher concurrency helps until I/O becomes the bottleneck.
  • Single file: On par with Node.js; small N-API overhead.

See Benchmarks (e.g. rm 2000 files, 4 threads: Node 92 ms vs Rush-FS 53 ms).

Notes

  • Recursive: When recursive: true, Rush-FS uses rayon  for parallel deletion. Default concurrency is 1 for safety; increase (e.g. 4) for large directories.
  • Windows: maxRetries and retryDelay help with transient “access denied” or locking issues. Same semantics as Node.js.
  • Symlinks: Recursive removal does not follow symlinks; the link is removed, not the target. Matches Node.js behavior.
Last updated on