Add a couple guides

This commit is contained in:
Jarred Sumner
2025-02-12 17:32:16 -08:00
parent a127f1ab59
commit 2ea879e29b
3 changed files with 57 additions and 1 deletions

View 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.

View 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.

View File

@@ -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.