Created
November 2, 2018 21:42
-
-
Save seansullivan/d6708b77843d68a38d238754290cd3c2 to your computer and use it in GitHub Desktop.
Parse CSV File with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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