Skip to main content
To recursively delete a directory and all its contents, use rm from node:fs/promises. This is like running rm -rf in JavaScript.
delete-directory.ts

These options configure the deletion behavior:
  • recursive: true - Delete subdirectories and their contents
  • force: true - Don’t throw errors if the directory doesn’t exist
You can also use it without force to ensure the directory exists:
delete-directory.ts

See Docs > API > FileSystem for more filesystem operations.