del, fs-extra, and rimraf are all npm packages designed to help developers delete files and directories in Node.js environments, but they differ significantly in scope, API design, and intended use cases. rimraf is a minimal utility that replicates the behavior of the Unix rm -rf command, offering a simple promise/callback-based interface for recursive deletion. del builds on top of globby to support glob patterns, enabling powerful batch deletions with fine-grained control over matching and exclusion rules. fs-extra is a comprehensive extension of Node.js’s built-in fs module that includes a .remove() method (which internally uses rimraf) alongside dozens of other file system utilities like copying, ensuring, and JSON operations.
All three packages solve the problem of deleting files and directories in Node.js, but they do so with different philosophies, capabilities, and trade-offs. Understanding their technical distinctions helps you avoid unnecessary bloat or missing functionality in your toolchain.
rimraf is purpose-built for one thing: recursively deleting files and folders, just like rm -rf in the terminal. It doesn’t care about patterns — you give it a path, and it removes it. Under the hood, it handles cross-platform quirks like Windows file locking by retrying with exponential backoff.
// rimraf: Delete a single directory
import rimraf from 'rimraf';
// Callback style
rimraf('./node_modules', (err) => {
if (err) console.error(err);
});
// Promise style (v3+)
await rimraf('./build');
del focuses on pattern-based deletion. It uses glob syntax to match multiple files or directories at once, making it ideal for cleaning up build artifacts or temporary files across complex directory structures.
// del: Delete multiple files using globs
import del from 'del';
// Remove all .log files except error.log
await del(['logs/*.log', '!logs/error.log']);
// Clean dist folder but keep license.txt
await del(['dist/**/*', '!dist/license.txt']);
fs-extra is not primarily a deletion library — it’s a full-featured extension of Node’s fs module. Its .remove() method wraps rimraf, so deletion is just one of many utilities it provides (e.g., .copy(), .ensureDir(), .readJson()).
// fs-extra: Remove using the same engine as rimraf
import { remove } from 'fs-extra';
await remove('./temp');
// But you might also use it for other tasks
await copy('./src', './dest');
const config = await readJson('./config.json');
This is where the biggest practical difference lies.
del: Full glob support via globby. Supports negation (!), brace expansion ({a,b}), and deep matching (**). Handles arrays of patterns and respects .gitignore by default (configurable).rimraf: No glob support. You must resolve paths yourself before passing them in.fs-extra: No built-in glob support in .remove(). If you need patterns, you’d have to combine it with another package like glob.If your task involves "delete everything in out/ except out/manifest.json", only del can express that concisely.
All three handle non-existent paths differently:
del: Silently ignores paths that don’t exist. Returns an array of deleted paths, so you can verify what was actually removed.rimraf: Also ignores non-existent paths — consistent with rm -rf behavior.fs-extra.remove(): Same as rimraf since it delegates to it.However, when it comes to permission errors or locked files:
rimraf (and by extension fs-extra) implements retry logic on Windows, which is critical for reliability in CI environments or when dealing with node_modules.del does not retry — it fails fast if a file can’t be deleted on the first attempt. This can be a gotcha in Windows-heavy workflows.rimraf has zero dependencies. It’s tiny and focused.del depends on globby, which pulls in fast-glob and related utilities. This adds weight but delivers powerful matching.fs-extra bundles many utilities, so if you’re not using its other features, including it just for .remove() adds unnecessary code.In a minimal CLI tool, rimraf is often the pragmatic choice. In a build pipeline using Webpack or Vite, del pairs naturally with existing glob-based configurations.
rimraf: Offers both callback and promise APIs. The promise version requires importing from rimraf/promises in older versions, but v3+ supports top-level await rimraf(...).del: Promise-only. Designed for async/await from the ground up.fs-extra: Fully promise-compatible with optional callback support, matching Node’s fs.promises style.If your codebase is strictly modern async/await, del and newer rimraf feel more natural. If you mix callbacks and promises, fs-extra and rimraf offer flexibility.
rimraf if:rimraf node_modules).del if:fs-extra if:rimraf’s behavior without adding another direct dependency.It’s common to see projects install both rimraf and del “just in case,” but this duplicates effort. Pick one based on whether you need globbing:
delrimraf (or fs-extra if already present)Remember: fs-extra.remove() is rimraf under the hood, so there’s no functional advantage to choosing one over the other for simple deletion — only ecosystem fit matters.
For most frontend build pipelines, del is the best fit because cleanup tasks almost always involve glob patterns (dist/**/*, coverage/, etc.).
For CLI tools, install scripts, or minimal utilities, rimraf is leaner and more predictable.
Only reach for fs-extra for deletion if you’re already leveraging its broader feature set — otherwise, it’s overkill.
Choose del when you need to delete multiple files or directories using glob patterns (e.g., dist/**/*, !dist/keep.js). It’s ideal for build scripts or cleanup tasks where pattern-based selection is essential. Its promise-first API integrates cleanly with modern async/await workflows, and it handles edge cases like non-existent paths gracefully by resolving rather than throwing.
Choose fs-extra if your project already depends on it for other file system operations (like copying directories or reading JSON files) and you want consistency across your I/O codebase. Its .remove() method offers the same recursive deletion capability as rimraf but within a broader toolkit. Avoid adding it solely for deletion — its full feature set may be overkill if you only need to remove files.
Choose rimraf when you need a lightweight, battle-tested utility that mimics rm -rf behavior exactly. It’s perfect for simple recursive deletions without globbing needs, especially in CLI tools or minimal scripts where dependency footprint matters. Its callback and promise APIs are straightforward, and it reliably handles permissions and locked files on Windows.
Delete files and directories using globs
Similar to rimraf, but with a Promise API and support for multiple files and globbing. It also protects you against deleting the current working directory and above.
npm install del
import {deleteAsync} from 'del';
const deletedFilePaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']);
const deletedDirectoryPaths = await deleteAsync(['temp', 'public']);
console.log('Deleted files:\n', deletedFilePaths.join('\n'));
console.log('\n\n');
console.log('Deleted directories:\n', deletedDirectoryPaths.join('\n'));
The glob pattern ** matches all children and the parent.
So this won't work:
deleteSync(['public/assets/**', '!public/assets/goat.png']);
You have to explicitly ignore the parent directories too:
deleteSync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
To delete all subdirectories inside public/, you can do:
deleteSync(['public/*/']);
Suggestions on how to improve this welcome!
Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use path.posix.join() instead of path.join().
Returns Promise<string[]> with the deleted paths.
Returns string[] with the deleted paths.
Type: string | string[]
See the supported glob patterns.
Type: object
You can specify any of the globby options in addition to the below options. In contrast to the globby defaults, expandDirectories, onlyFiles, and followSymbolicLinks are false by default.
Type: boolean
Default: false
Allow deleting the current working directory and outside.
Type: boolean
Default: false
See what would be deleted.
import {deleteAsync} from 'del';
const deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true});
console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n'));
Type: boolean
Default: false
Allow patterns to match files/folders that start with a period (.).
This option is passed through to fast-glob.
Note that an explicit dot in a portion of the pattern will always match dot files.
Example
directory/
├── .editorconfig
└── package.json
import {deleteSync} from 'del';
deleteSync('*', {dot: false});
//=> ['package.json']
deleteSync('*', {dot: true});
//=> ['.editorconfig', 'package.json']
Type: number
Default: Infinity
Minimum: 1
Concurrency limit.
Type: (progress: ProgressData) => void
Called after each file or directory is deleted.
import {deleteAsync} from 'del';
await deleteAsync(patterns, {
onProgress: progress => {
// …
}});
{
totalCount: number,
deletedCount: number,
percent: number,
path?: string
}
percent is a value between 0 and 1path is the absolute path of the deleted file or directory. It will not be present if nothing was deleted.See del-cli for a CLI for this module and trash-cli for a safe version that is suitable for running by hand.