File system

fs/promises.appendFile()

Appends bytes to a file, creating it if needed with the normal append flag. Tested on Node.js 22.16.0. Appending is not a substitute for transactional logging or a durable message queue.

Formal Syntax & Structure

nodejs syntaxnodejs
fsPromises.appendFile(path, data[, options])

Parameters & Attributes

NameTypeDescription
pathstring | Buffer | URL | FileHandleDestination.
datastring | BufferData to append.
optionsstring | objectEncoding or options such as flag, mode and flush.

Return Value

Promise<void>

Resolves after append completes.

Working Example

Example Snippetnodejs
import * as fs from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';const dir=await fs.mkdtemp(join(tmpdir(),'bytemind-ref-'));try {  const file=join(dir,'events.txt');  await fs.appendFile(file,'created\n');  await fs.appendFile(file,'packed\n');  console.log(JSON.stringify(await fs.readFile(file,'utf8')));} finally { await fs.rm(dir,{recursive:true,force:true}); }
Node.js Reference