Created
February 16, 2016 10:34
-
-
Save beeva-manueldepaz/1a3cdc82727721ab5107 to your computer and use it in GitHub Desktop.
Example of usage node package: csv-to-json
This file contains 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
/* | |
_ _ | |
| | (_) | |
___ _____ ________| |_ ___ ______ _ ___ ___ _ __ | |
/ __/ __\ \ / /______| __/ _ \______| / __|/ _ \| '_ \ | |
| (__\__ \\ 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