Skip to content

Instantly share code, notes, and snippets.

@andriyankov
Last active February 10, 2021 09:55
Show Gist options
  • Select an option

  • Save andriyankov/82b1446c4fca8690fb0c1180f20c74be to your computer and use it in GitHub Desktop.

Select an option

Save andriyankov/82b1446c4fca8690fb0c1180f20c74be to your computer and use it in GitHub Desktop.
Example CSV reading with PapaParse and callback functions using
const fs = require('fs');
const Papa = require('papaparse'); // https://www.papaparse.com/
function readCSVFile(filepath, cb) {
Papa.parse(fs.ReadStream(filepath), {
complete: (results, file) => cb(null, results.data, file),
error: (err, file) => cb(err, null, file)
});
}
(() => {
const filepath = 'c:\\Projects\\javascript-workspace\\SwimAnalyse\\examples\\garmin';
const filename = 'activity_5558250880.csv';
readCSVFile(`${filepath}\\${filename}`,
(err, result, file) => {
if (err) {
console.error(err);
} else {
console.log(result);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment