Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
August 30, 2023 13:25
May 11, 2017 20:30
November 27, 2018 01:14
November 27, 2018 01:14
November 27, 2018 01:14
July 19, 2022 16:23
August 30, 2023 23:42
August 30, 2023 23:42
July 19, 2022 16:15
September 26, 2020 02:00
August 30, 2023 23:45
August 30, 2023 23:42
August 30, 2023 23:42


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('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:


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

deleteAsync(patterns, options?)

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

deleteSync(patterns, options?)

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.


├── .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 1
  • path 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.

del for enterprise

Available as part of the Tidelift Subscription.

The maintainers of del and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

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