Node csv-parser return variable

120 Views Asked by At

I have this function

validarcsv(){

 let text;
 fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (data) => results.push(data))
  .on('end', () => {
    text = result[0].something
    return text;
  });

}

and what i'm triyng to do is retrieve the value of the function like this

let value = validarcsv();
console.log(value);

it's showing me undefined how can i return the value of that function i'm stuck on that one

1

There are 1 best solutions below

0
On

You return nothing in validarcsv(). If you create a variable and assign it to results and return it at the end it should work.