Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Created November 2, 2018 21:42
Show Gist options
  • Save seansullivan/d6708b77843d68a38d238754290cd3c2 to your computer and use it in GitHub Desktop.
Save seansullivan/d6708b77843d68a38d238754290cd3c2 to your computer and use it in GitHub Desktop.
Parse CSV File with Node.js
const fs = require('fs');
const parse = require('csv-parse');
/**
* Retrieve data to process
*
* @return {Promise}
*/
const getData = (csvFilenameToParse) => {
return new Promise((resolve, reject) => {
const input = fs.readFileSync(csvFilenameToParse).toString('utf8');
const records = parse(input, { columns: true }, (error, output) => {
if (error) {
return reject(error);
}
resolve(output);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment