del vs fs-extra vs rimraf
File System Deletion Utilities in Node.js Projects
delfs-extrarimrafSimilar Packages:

File System Deletion Utilities in Node.js Projects

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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
del12,739,0841,34312.7 kB176 months agoMIT
fs-extra09,62457.7 kB1212 days agoMIT
rimraf05,838262 kB8a month agoBlueOak-1.0.0

del vs fs-extra vs rimraf: Choosing the Right File Deletion Tool

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.

🗑️ Core Purpose and Scope

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');

🔍 Pattern Matching: Glob Support

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.

⚙️ Error Handling and Edge Cases

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.

📦 Dependency Footprint and Integration

  • 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.

🔄 API Style and Modern JavaScript

  • 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.

🛠️ When to Use Which?

Use rimraf if:

  • You’re writing a script that deletes one known path (e.g., rimraf node_modules).
  • You need maximum reliability on Windows with retry logic.
  • You want the smallest possible dependency.

Use del if:

  • You’re cleaning build outputs with complex inclusion/exclusion rules.
  • Your workflow already uses glob patterns elsewhere (e.g., in ESLint or Prettier configs).
  • You prefer a clean, promise-only API and don’t mind the extra dependencies.

Use fs-extra if:

  • You’re already using it for other file operations (copying, JSON handling, etc.).
  • You want a unified I/O interface across your project.
  • You don’t need globbing and want rimraf’s behavior without adding another direct dependency.

💡 Pro Tip: Don’t Mix Them Unnecessarily

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:

  • Need patterns? → del
  • Just deleting fixed paths? → rimraf (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.

✅ Final Recommendation

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.

How to Choose: del vs fs-extra vs rimraf

  • del:

    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.

  • fs-extra:

    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.

  • rimraf:

    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.

README for del

del

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.

Install

npm install del

Usage

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'));

Beware

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!

API

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().

deleteAsync(patterns, options?)

Returns Promise<string[]> with the deleted paths.

deleteSync(patterns, options?)

Returns string[] with the deleted paths.

patterns

Type: string | string[]

See the supported glob patterns.

options

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.

force

Type: boolean
Default: false

Allow deleting the current working directory and outside.

dryRun

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'));
dot

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']
concurrency

Type: number
Default: Infinity
Minimum: 1

Concurrency limit.

onProgress

Type: (progress: ProgressData) => void

Called after each file or directory is deleted.

import {deleteAsync} from 'del';

await deleteAsync(patterns, {
	onProgress: progress => {
	// …
}});
ProgressData
{
	totalCount: number,
	deletedCount: number,
	percent: number,
	path?: string
}
  • percent is a value between 0 and 1
  • path is the absolute path of the deleted file or directory. It will not be present if nothing was deleted.

CLI

See del-cli for a CLI for this module and trash-cli for a safe version that is suitable for running by hand.

Related

  • make-dir - Make a directory and its parents if needed
  • globby - User-friendly glob matching