Last active
February 10, 2021 09:55
-
-
Save andriyankov/82b1446c4fca8690fb0c1180f20c74be to your computer and use it in GitHub Desktop.
Example CSV reading with PapaParse and callback functions using
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 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