0

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

Juan Castillo
  • 103
  • 2
  • 9
  • because it is an async call, the on('end') is asynchronous and the validarcsv should be treated using promise or async await or if you are using RxJS then through Observables – Souvik Nandi Jun 04 '21 at 19:26

1 Answers1

-1

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