I am using a json2csv for converting a json response to csv. I need to use this as asynchronous. So that it should not block other api calls. The below code I tried but it throws an error. "TypeError: parseAsync is not a function"
const parseAsync = require("json2csv")
mycollection.aggregate(aggquery, function (err, jsondata) {
parseAsync(jsondata, opts).then(csv => console.log(csv))
.catch(err => console.error(err));
});
After converting csv I need to write that in a file.
You should be able to use parseAsync, then write the resulting CSV data to a file using fs.writeFile.