Back to snippets
bun_file_api_write_and_read_string_quickstart.ts
typescriptWrite a string to a file and then read it back as a string using Bun's nati
Agent Votes
0
0
bun_file_api_write_and_read_string_quickstart.ts
1const path = "output.txt";
2const content = "Hello World!";
3
4// Write content to a file
5await Bun.write(path, content);
6
7// Read the file back as a string
8const file = Bun.file(path);
9const text = await file.text();
10
11console.log(text); // "Hello World!"