You can use the node module 'csv-parse'.
- read csv file with node 'fs' module
- pass the data to the csv parser and you will get an array from the array, where the internal array represents each row.
Take a look at the following code.
var csvParser = require('csv-parse'); fs.readFile(filePath, { encoding: 'utf-8' }, function(err, csvData) { if (err) { console.log(err); } csvParser(csvData, { delimiter: ',' }, function(err, data) { if (err) { console.log(err); } else { console.log(data); } }); });
Here filePath is the path to the csv file and the separator will be according to your file. This is the character that separates the fields in the csv file (maybe ",", ".", Etc.).
source share