I was hoping someone could shed some light on this for me... I can't for the life of me work out how to append data using nodejs and ya-csv(module) to a pre-existing csv file. (in this case called staff.csv) If I were to run this script twice the csv file would be overwritten rather than updated to hold both the old and new information. Don't suppose anyone out there has a decent grasp of ya-csv and could help me out or knows of an alternative?
dictionary = {
//data...
};
var csv = require('ya-csv');
var w = csv.createCsvFileWriter('staff.csv');
var data = [];
for(key in dictionary) {
if(typeof dictionary[key] !== 'function'){
data.push(key);
data.push(dicitonary[key]);
}
}
w.writeRecord(data);
Try to pass correct options
object to createCsvFileWriter
function:
var w = csv.createCsvFileWriter('staff.csv', {'flags': 'a'});
'a'
here means "append". It allows you to add content to the end of an existing file. For all avaliable flags see Nodejs Documentation.