Use this file to discover all available pages before exploring further.
Bun.file and Bun.write are heavily optimized and are the recommended way to perform file-system tasks in Bun. For operations not yet available natively—such as mkdir or readdir—use Bun’s nearly complete implementation of node:fs.
You can create a BunFile using a path string, a file descriptor number, or a file:// URL:
Bun.file("foo.txt"); // relative to cwdBun.file("/absolute/path/to/foo.txt"); // absolute pathBun.file(1234); // file descriptor numberBun.file(new URL(import.meta.url)); // reference to the current file
Bun.write(destination, data) writes data to disk and returns a Promise<number> (bytes written).Destination can be a string path, file:// URL, or BunFile. Data can be a string, Blob, BunFile, ArrayBuffer, TypedArray, or Response.
await Bun.write("output.txt", "Hello, world!");
Bun automatically selects the fastest available system call for each input/output combination (e.g., copy_file_range on Linux, clonefile on macOS).
Bun provides module-relative path helpers on import.meta:
import.meta.dir; // absolute path to the directory of the current fileimport.meta.file; // filename of the current file (e.g. "index.ts")import.meta.path; // absolute path to the current file
These are useful for constructing paths relative to the current source file:
Bun.Glob provides fast native file globbing. Use it to scan directories or match strings against patterns.
import { Glob } from "bun";// Scan a directory for all TypeScript filesconst glob = new Glob("**/*.ts");for await (const file of glob.scan(".")) { console.log(file); // "src/index.ts", "src/utils/helpers.ts", ...}