Migration

DEP0147: migrate recursive rmdir

Replace deprecated recursive rmdir with rm when deleting a controlled tree. Never pass an unvalidated or user-chosen directory to recursive removal. Tested on Node.js 22.16.0. Example output (one line per entry): ["ENOENT"].

Formal Syntax & Structure

nodejs syntaxnodejs
fs.rm(path, { recursive: true, force: true })

Return Value

Migration outcome

Replacement behavior shown by the example.

Working Example

Example Snippetnodejs
import { mkdtemp, mkdir, rm, access } from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';const d = await mkdtemp(join(tmpdir(), 'bytemind-'));try {    const owned = join(d, 'cache');    await mkdir(owned);    await rm(owned, { recursive: true, force: true });    try {        await access(owned);    }    catch (e) {        console.log(e.code);    }}finally {    await rm(d, { recursive: true, force: true });}
Node.js Reference