I'm trying to use 'csv-parser' module from node.js environment. I successfully read my csv document and I got an array 'results' with all the information I need in .json format. The first console.log print all the data, but the second one print an empty array (as declared). Why am I having this scope problem and how can I fix it? Thanks all of you in advance.
const csv = require('csv-parser');
const fs = require('fs');
let results = [];
fs.createReadStream('MyData.csv')
    .pipe(csv())
    .on('data', data => results.push(data))
    .on('end', () => {
        console.log(results) //1st console.log
        console.log('CSV file successfully processed');
    });
console.log(results);//2nd console.log
 
     
    