Node.js Read CSV File

December 13, 2021
npm i -S fast-csv
const csv = require('@fast-csv/parse');

// with error handling and end notification
csv.parseFile('data/data.csv')
  .on('error', error => console.error(error))
  .on('data', row => console.log(`ROW=${JSON.stringify(row)}`))
  .on('end', rowCount => console.log(`Parsed ${rowCount} rows`));


// read data with header
csv.parseFile('data/data.csv', {headers: true})
  .on('data', row => {
    console.log(row)
  })
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.