Skip to content

Commit

Permalink
Update unlink.md guide (#16268)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjjd84 authored Jan 11, 2025
1 parent 1e67665 commit 96dc7ed
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions docs/guides/write-file/unlink.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
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.)
To delete a file in Bun, use the `delete` method.

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

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);
await file("./path-to-file.txt").delete();
```

0 comments on commit 96dc7ed

Please sign in to comment.