I have this function
function getData(file, type) {
let data = [];
fs.createReadStream(file)
.pipe(csv({headers: false, separator: ';',}))
.on('data', (row) => {
let item = {
date: row[0],
value: row[1]
};
let item2 = {
date: moment(row[0], "DD-MM-YYYY HH:mm").add(30, "minutes").format("DD/MM/YYYY HH:mm"),
value: row[2]
};
data.push(item);
data.push(item2);
})
.on('end', () => {
return data;
});
}
and I would like to return the data parsed in the csv, but when I return data in the .on method, data is empty.
How should I do it ?
.on('error', (err) => {see if you have no issue. Also put the.on('data', (row) => {function into atry/catch