0

I am new to node.js. I have to email the retrieved data in CSV format. I wrote code and it is working fine but with an empty array the headers are not included in the CSV, I get an empty excel sheet.

I used

var fastcsv = require("fast-csv");
var format = require('@fast-csv/format');

var csv = fastcsv.write(finalData, {headers: true});

I tried the code below, but it gives me the "format is not a function" error

var csv = fastcsv.write(finalData, {headers: true});
var csv = csv.format({alwaysWriteHeaders:true})

please help

mural
  • 29
  • 1
  • 8

1 Answers1

0

Try use it like this, restructure it.

var fastcsv = require("fast-csv"); 
var { format } = require('@fast-csv/format');

var csv = fastcsv.write(finalData, {headers: true}); 
var formated = format({ alwaysWriteHeaders:true })
console.log(formated)
mandaputtra
  • 922
  • 3
  • 18
  • 36