Get original line in the file using csv-parser in Node js

167 Views Asked by At

I am using csv-parser (https://www.npmjs.com/package/csv-parser) to parse the CSV file something like below:

const csv = require('csv-parser')
const fs = require('fs')
const results = [];

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (data) => results.push(data))
  .on('end', () => {
    console.log(results);
    // [
    //   { NAME: 'Daffy Duck', AGE: '24' },
    //   { NAME: 'Bugs Bunny', AGE: '22' }
    // ]
  });

The data comes for each line here is of JSON format which is pretty good as its easy to get values and all? Is it also possible in csv-parser to get the original line as well pretty easily. If so, how can I do that?

0

There are 0 best solutions below