mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Add a couple guides
This commit is contained in:
37
docs/guides/runtime/delete-directory.md
Normal file
37
docs/guides/runtime/delete-directory.md
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
name: Delete directories
|
||||
---
|
||||
|
||||
To recursively delete a directory and all its contents, use `rm` from `node:fs/promises`. This is like running `rm -rf` in JavaScript.
|
||||
|
||||
```ts
|
||||
import { rm } from "node:fs/promises";
|
||||
|
||||
// Delete a directory and all its contents
|
||||
await rm("path/to/directory", { recursive: true, force: true });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
These options configure the deletion behavior:
|
||||
|
||||
- `recursive: true` - Delete subdirectories and their contents
|
||||
- `force: true` - Don't throw errors if the directory doesn't exist
|
||||
|
||||
You can also use it without `force` to ensure the directory exists:
|
||||
|
||||
```ts
|
||||
try {
|
||||
await rm("path/to/directory", { recursive: true });
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") {
|
||||
console.log("Directory doesn't exist");
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > FileSystem](https://bun.sh/docs/api/file-io) for more filesystem operations.
|
||||
19
docs/guides/runtime/delete-file.md
Normal file
19
docs/guides/runtime/delete-file.md
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Delete files
|
||||
---
|
||||
|
||||
To delete a file, use `Bun.file(path).delete()`.
|
||||
|
||||
```ts
|
||||
// Delete a file
|
||||
const file = Bun.file("path/to/file.txt");
|
||||
await file.delete();
|
||||
|
||||
// Now the file doesn't exist
|
||||
const exists = await file.exists();
|
||||
// => false
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > FileSystem](https://bun.sh/docs/api/file-io) for more filesystem operations.
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
name: Track memory usage using V8 heap snapshots
|
||||
name: Inspect memory usage using V8 heap snapshots
|
||||
---
|
||||
|
||||
Bun implements V8's heap snapshot API, which allows you to create snapshots of the heap at runtime. This helps debug memory leaks in your JavaScript/TypeScript application.
|
||||
|
||||
Reference in New Issue
Block a user