Aman Varshney
Aman Varshney

Reputation: 56

How to append data(new row) at new line or row to existing csv file by using fast-csv npm

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

Answers (1)

Viet Nguyen
Viet Nguyen

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

Related Questions