fs.appendFileSync in nodeJs

const fs = require('fs');

const filePath = 'example.txt';
const dataToAppend = 'This is the data to append.';

try {
  fs.appendFileSync(filePath, dataToAppend, 'utf8');
  console.log('Data has been appended to the file successfully.');
} catch (err) {
  console.error('Error appending data to the file:', err);
}