create csv file nodejs

const fs = require('fs');

const data = [
  ['Name', 'Age', 'Country'],
  ['John Doe', 30, 'USA'],
  ['Jane Smith', 25, 'Canada'],
  ['Alice Johnson', 35, 'UK']
];

const csvContent = data.map(row => row.join(',')).join('\n');

fs.writeFile('data.csv', csvContent, err => {
  if (err) {
    console.error('Error creating CSV file:', err);
    return;
  }
  console.log('CSV file has been created');
});