Reputation: 56
I am trying to add/write data to existing csv file using 'fast-csv' npm. But it's appending new data to be written in the last row written in file it's not writing a new row for it as headers are also same.
I have tried below code for appending data:
csv.writeToStream(fs.createWriteStream('test.csv', { flags: 'a' }), [dataObj], { headers: false }).on("finish", function() {
console.log("file written successfully")
})
want to know is there any way to add data to new row ?
Upvotes: 2
Views: 4371
Reputation: 66
You might need to configure the includeEndRowDelimiter as true, please check the docs at: fast-csv document, section Formatting. Lets try the following:
{ flags: 'a', includeEndRowDelimiter: true }
Upvotes: 5