Skip to main content
Bun provides fast file writing with Bun.write().

Write String to File

await Bun.write("output.txt", "Hello World");

Write JSON

const data = { name: "John", age: 30 };
await Bun.write("data.json", JSON.stringify(data, null, 2));

Append to File

const file = Bun.file("log.txt");
await Bun.write(file, "New log entry\n", { append: true });
See File I/O for complete documentation.

Build docs developers (and LLMs) love