Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/zhcndoc/bun/llms.txt

Use this file to discover all available pages before exploring further.

Bun provides fast file reading with Bun.file().

Read File to String

const file = Bun.file("data.txt");
const text = await file.text();
console.log(text);

Synchronous Read

import { readFileSync } from "node:fs";

const text = readFileSync("data.txt", "utf-8");
console.log(text);

Error Handling

try {
  const file = Bun.file("data.txt");
  const text = await file.text();
  console.log(text);
} catch (error) {
  console.error("Failed to read file:", error);
}
See File I/O for complete documentation.

Build docs developers (and LLMs) love