talira

Delete files and directories by glob in Node.js, with a promise API

open sourceMITfree

del is a Node.js package that deletes files and directories matching glob patterns, like rimraf but with a promise API, several patterns at once and negated patterns to keep paths. It refuses to delete the current working directory and the directories above it unless forced, offers a dry run that returns what would be deleted, a concurrency limit, and gitignore-aware exclusions through globby, and returns the deleted paths.

Problems it solves

  • clean a build directory with glob patterns in a Node.js script
  • delete files matching a pattern but keep a few, in Node
  • preview which files a cleanup script would delete

Features

  • deletes files and directories by glob patterns, with negations
  • promise-based deleteAsync and synchronous deleteSync
  • protects the working directory and its parents unless forced
  • dry run that returns the paths it would delete
  • concurrency limit and gitignore-aware exclusions

Limitations

  • Glob patterns can only use forward slashes; Windows paths with glob characters need path.posix.join()1

Alternatives

The same job

These do what del does.

  1. rimraf rm -rf for Node.js, cross-platform
  2. globby Glob matching for Node.js with negated patterns, directory expansion and .gitignore support
  3. glob Match files using the patterns the shell uses
  4. minimatch Glob matching for JavaScript, without regular expressions
  5. fast-glob Very fast and efficient glob library for Node.js

Compare del with the top 3