I'm trying to get a CSV File Header through a method, but it has a very weird syntax. This is what I tried so far and I understand that I'm not receiving anything because it's working asynchronous. I tried other solutions like async
, await
but I really don't have so much experience. I'm also using csv-parser package to get the headers only.
This is what I'm trying to do:
"file.getHeader"(_id) {
const future = new Future();
fs.createReadStream("file.csv")
.pipe(csv())
.on("headers", headerList => {
future.return(headerList[0]);
})
.on("error", error => {
future.return(error);
});
return future.wait();
}
If you also have some useful links to help me deal with the problem please paste them here. Thank you.