# Append content to a file (/docs/guides/write-file/append)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 272 · updated: 2026-07-28 -->
Related: [Write a string to a file](/docs/guides/write-file/basic.md), [Write a Blob to a file](/docs/guides/write-file/blob.md), [Write a file to stdout](/docs/guides/write-file/cat.md), [Copy a file to another location](/docs/guides/write-file/file-cp.md), [Write a file incrementally](/docs/guides/write-file/filesink.md), [Write a Response to a file](/docs/guides/write-file/response.md)

Bun implements the `node:fs` module, which includes the `fs.appendFile` and `fs.appendFileSync` functions for appending content to files.

***

`fs.appendFile` asynchronously appends data to a file, creating the file if it does not yet exist. The content can be a string or a `Buffer`.

```ts
import { appendFile } from "node:fs/promises";

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

***

To use the non-`Promise` API:

```ts
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
import { appendFile } from "node:fs";

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

***

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

```ts
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 `fs.appendFile`.
