Skip to content

Instantly share code, notes, and snippets.

@beeva-manueldepaz
Created February 16, 2016 10:34
Show Gist options
  • Save beeva-manueldepaz/1a3cdc82727721ab5107 to your computer and use it in GitHub Desktop.
Save beeva-manueldepaz/1a3cdc82727721ab5107 to your computer and use it in GitHub Desktop.
Example of usage node package: csv-to-json
/*
_ _
| | (_)
___ _____ ________| |_ ___ ______ _ ___ ___ _ __
/ __/ __\ \ / /______| __/ _ \______| / __|/ _ \| '_ \
| (__\__ \\ V / | || (_) | | \__ \ (_) | | | |
\___|___/ \_/ \__\___/ | |___/\___/|_| |_|
_/ |
|__/
Demo purpose file:
usage:
$ npm install csv-to-json
$ node parse.js
*/
var csv = require('csv-to-json');
var parse = function(resolve,reject) {
csv.parse( { filename:"Input.csv"},
(err,json) => {
if (err) { reject(err); }
resolve(json);
});
};
var save = function(input) {
csv.writeJsonToFile({ filename: "output.json", json: input }, (err) => { if (err) { fail(err); } });
};
var fail = function(reason) {
console.log('Handle rejected promise ('+reason+') here.');
}
var p1 = new Promise(parse);
p1.then(save)
.catch(fail);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment