Been struggling for several hours now trying to import CSV, uploaded from client using meteor-file and converted to CSV using node-csv serv
So it turns out because CSV() uses a callback and runs Asynchronous code, I needed to use a 'Future'. For more explaination see http://gist.io/3443021
here's my working code:
Meteor.methods({
'uploadFile': function (file) {
Future = Npm.require('fibers/future');
console.log(file.name+'\'+file.type+'\'+file.size);
file.save('/home/russell/tmp',{});
var buffer = new Buffer(file.data);
// Set up the Future
var fut = new Future();
// Convert buffer (a CSV file) to an array
CSV().from(
buffer.toString(),
{comment: '#', delimiter: ',', quote: ''}
)
.to.array( function(data){
var newRecords=[];
for(var row=0; row
});