# del

> Delete files and directories

Latest version **8.0.1** (published 2025-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install del
pnpm add del
yarn add del
bun add del
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 8.0.1 |
| Published | 2025-09-18 |
| First published | 2014-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 7 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1343 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | delete, files, folders, directories, remove, destroy, trash, unlink, clean, cleaning, cleanup, rm, rmrf, rimraf, rmdir, glob, gulpfriendly, file, folder, directory, fs, filesystem |

## Links

- npm: https://www.npmjs.com/package/del
- Repository: https://github.com/sindresorhus/del
- Homepage: https://github.com/sindresorhus/del#readme
- Issues: https://github.com/sindresorhus/del/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/del

## Dependencies (7)

- [p-map](https://npm.io/package/p-map.md) ^7.0.2
- [slash](https://npm.io/package/slash.md) ^5.1.0
- [globby](https://npm.io/package/globby.md) ^14.0.2
- [is-glob](https://npm.io/package/is-glob.md) ^4.0.3
- [is-path-cwd](https://npm.io/package/is-path-cwd.md) ^3.0.0
- [is-path-inside](https://npm.io/package/is-path-inside.md) ^4.0.0
- [presentable-error](https://npm.io/package/presentable-error.md) ^0.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 8.0.1 (latest) — 2025-09-18
- 8.0.0 — 2024-10-07
- 7.1.0 — 2023-08-30
- 7.0.0 — 2022-07-19
- 6.1.1 — 2022-05-24
- 6.1.0 — 2022-05-16
- 6.0.0 — 2020-09-26
- 5.1.0 — 2019-08-23
- 5.0.0 — 2019-07-02
- 4.1.1 — 2019-04-28
- 4.1.0 — 2019-04-01
- 4.0.0 — 2019-03-03
- 3.0.0 — 2017-06-09
- 2.2.2 — 2016-08-13
- 2.2.1 — 2016-06-21
- … 14 more at https://npm.io/package/del/versions

## README

# del

> Delete files and directories using [globs](https://github.com/sindresorhus/globby#globbing-patterns)

Similar to [rimraf](https://github.com/isaacs/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

```sh
npm install del
```

## Usage

```js
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:

```js
deleteSync(['public/assets/**', '!public/assets/goat.png']);
```

You have to explicitly ignore the parent directories too:

```js
deleteSync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
```

To delete all subdirectories inside `public/`, you can do:

```js
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](https://github.com/sindresorhus/globby#globbing-patterns).

- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)
- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)

#### options

Type: `object`

You can specify any of the [`globby` options](https://github.com/sindresorhus/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.

```js
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`](https://github.com/mrmlnc/fast-glob#dot).

Note that an explicit dot in a portion of the pattern will always match dot files.

**Example**

```
directory/
├── .editorconfig
└── package.json
```

```js
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.

```js
import {deleteAsync} from 'del';

await deleteAsync(patterns, {
	onProgress: progress => {
	// …
}});
```

###### ProgressData

```js
{
	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](https://github.com/sindresorhus/del-cli) for a CLI for this module and [trash-cli](https://github.com/sindresorhus/trash-cli) for a safe version that is suitable for running by hand.

## Related

- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
- [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching

---
_Source: https://npm.io/package/del · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
