fs.rm()

Removes files and directories, optionally recursively.

Since Node 14.14 Spec ↗

Syntax

await rm(path[, options])

Parameters

NameTypeRequiredDescription
path string | Buffer | URL Yes The path to remove.
options object No `force` (ignore missing path), `recursive` (remove directory trees), `maxRetries`, and `retryDelay`.

Returns

Promise<void> — Resolves once the path is removed.

Examples

import { rm } from 'node:fs/promises';

await rm('./tmp', { recursive: true, force: true });
console.log('cleaned');
Output
cleaned
import { rm } from 'node:fs/promises';

await rm('./old.log', { force: true });

Notes

`rm` replaces the deprecated `rmdir({ recursive: true })`. Use `recursive: true` to delete non-empty directories and `force: true` to avoid `ENOENT` when the path may not exist. There is no undo.

See also