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.
According to the json2csv docs,
parseAsync()is not the default export but a property of the export instead. In other words, instead of this:...you want this:
That will get you past the error you're seeing about
parseAsync()not being a function.