I got this error in Hapijs mongoose project. Dont know where Iam going wrong. Anybody can help?
exportCsvFile method:
exportCsvFile: async function (req, h) {
// export csv file
try {
await Family.find({}).lean().exec((err, data) => {
if (err) throw err;
const csvFields = ['id','client_id','catalog_id','name','no_of_products','no_of_attributes','no_of_mandatory',
'image','fileLocation','status','created_by','updated_by'];
console.log(csvFields);
const json2csvParser = new Json2csvParser({
csvFields
});
const csvData = json2csvParser.parse(data);
fs.writeFile("family.csv", csvData, function(error) {
if (error) throw error;
console.log("Write to family.csv successfully!");
});
return h.response({
message: 'File downloaded Successfully'
}).code(200);
});
} catch (error) {
console.error("Error in export csv file method");
return h.response({ error: responseMessages.internal_server_error }).code(500);
}
},