Append text into a file nodejs

const fs = require('fs');

const textToAdd = 'This is the text to append to the file.\n';

fs.appendFile('example.txt', textToAdd, (err) => { if (err) throw err; console.log('Text was appended to the file.'); });