skills/bun-guides-write-file-append/SKILL.md
Append content to a file
npx skillsauth add jarle/bun-skills Bun Append content to a fileInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Bun implements the node:fs module, which includes the fs.appendFile and fs.appendFileSync functions for appending content to files.
You can use fs.appendFile to asynchronously append data to a file, creating the file if it does not yet exist. The content can be a string or a Buffer.
import { appendFile } from "node:fs/promises";
await appendFile("message.txt", "data to append");
To use the non-Promise API:
import { appendFile } from "node:fs";
appendFile("message.txt", "data to append", err => {
if (err) throw err;
console.log('The "data to append" was appended to file!');
});
To specify the encoding of the content:
import { appendFile } from "node:fs";
appendFile("message.txt", "data to append", "utf8", callback);
To append the data synchronously, use fs.appendFileSync:
import { appendFileSync } from "node:fs";
appendFileSync("message.txt", "data to append", "utf8");
See the Node.js documentation for more information.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling