# Bun Append content to a file

> Append content to a file

- Skill: `jarle/bun-append-content-to-a-file` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jarle/bun-append-content-to-a-file`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jarle/bun-append-content-to-a-file/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jarle (https://skillmd.com/u/jarle)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/jarle/bun-append-content-to-a-file

---


# Append content to a file

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`.

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
import { appendFile } from "node:fs/promises";

await appendFile("message.txt", "data to append");
```

***

To use the non-`Promise` API:

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
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:

```js  theme={"theme":{"light":"github-light","dark":"dracula"}}
import { appendFile } from "node:fs";

appendFile("message.txt", "data to append", "utf8", callback);
```

***

To append the data synchronously, use `fs.appendFileSync`:

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
import { appendFileSync } from "node:fs";

appendFileSync("message.txt", "data to append", "utf8");
```

***

See the [Node.js documentation](https://nodejs.org/api/fs.html#fspromisesappendfilepath-data-options) for more information.

