Skip to content

Instantly share code, notes, and snippets.

@brandonhall
Created January 26, 2012 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonhall/973e70bde8e6a530c489 to your computer and use it in GitHub Desktop.
Save brandonhall/973e70bde8e6a530c489 to your computer and use it in GitHub Desktop.
Dynamic CSV File Failing
processCSV:function (filename) {
if (filename.indexOf("download") !== -1) {
console.log('Here: ' + filename);
var jsonObj = [];
csv()
.fromPath(__dirname + '/csv/' + filename, {
columns:true
})
.on('data', function (data) {
if (data['E-mail Address'] !== null && data['First Name'] !== null) {
if(data['Last Name'] !== null) {
jsonObj.push({'name':data['First Name'] + ' ' + data['Last Name'], 'email':data['E-mail Address']});
} else {
jsonObj.push({'name':data['First Name'], 'email':data['E-mail Address']});
}
}
})
.on('error',function(error){
console.log(error.message);
})
.on('end', function () {
getContacts.returnObject(jsonObj, filename);
});
} else if (filename == 'ERROR') {
console.log('Unable to get contacts');
} else if (filename == 'TIMEOUT') {
console.log('Unfortunately, your request timed out');
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment