aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/write-file/unlink.md
blob: ba0cbe8b1d361119b736d7be69490921a538b7ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
---
name: Delete a file
---

To synchronously delete a file with Bun, use the `unlinkSync` function from the [`node:fs`](https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback) module. (Currently, there is no `Bun` API for deleting files.)

```ts
import { unlinkSync } from "node:fs";

const path = "/path/to/file.txt";
unlinkSync(path);
```

---

To remove a file asynchronously, use the `unlink` function from the [`node:fs/promises`](https://nodejs.org/api/fs.html#fs_fspromises_unlink_path) module.

```ts
import { unlink } from "node:fs/promises";

const path = "/path/to/file.txt";
await unlink(path);
```
href='/ansg191/bun/commit/src/io/io_linux.zig?h=jarred/fix-proxy-regression&id=b5cec4b70491984b2efb86a529a0fea6b112660f&follow=1'>[linux][http] return errno instead of unexpectedGravatar Jarred Sumner 1-2/+31 2022-01-23[http] Remove usages of `unreachable` in syscall error handlingGravatar Jarred Sumner 1-10/+0 2022-01-23Update io_linux.zigGravatar Jarred Sumner 1-0/+1 2022-01-23Use non-cancellable syscalls for HTTP & use errno for errorsGravatar Jarred Sumner 3-78/+933 2022-01-23Improve error message when `bun upgrade` failsGravatar Jarred Sumner 1-1/+1 2022-01-23NiceGravatar Jarred Sumner 1-1/+1 2022-01-23Update analytics_thread.zigGravatar Jarred Sumner 1-0/+8