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:
filePath<string>data<string>|<Buffer>|<Object>|<Unit8Array>- Returns:
Promise<any>
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