Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.36 KB

appendFile.md

File metadata and controls

43 lines (33 loc) · 1.36 KB

appendFile(filePath, data, options)

Append data to a file asynchronously. This method wraps writeFile with the append ('a') flag, allowing new data to be added at the end of the file seamlessly.

Alias: appendFile()

Parameters:

Example

const fs = require('fsmate');

const file = '/tmp/dir/subdir/file.txt';
const data = 'Hello World!';

// With Promises:
fs.appendFile(file, data)
.then(() => {
  console.log('success');
}).catch(e => {
  console.log(e);
});

// With async/await:
async function appendFile(f, content) {
  try {
    await fs.appendFile(f, content);
    console.log('success');
  } catch(err) {
    console.log(err);
  }
}

appendFile(file, data);

For the synchronous version, see: appendFileSync