Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  51] [ 6]  / answers: 1 / hits: 36600  / 8 Years ago, sat, december 3, 2016, 12:00:00

I am currently using csv-write-stream to write something to a csv file:



var fs = require('fs');
var csvWriter = require('csv-write-stream')

var writer = csvWriter()
writer.pipe(fs.createWriteStream('out.csv'))
writer.write({hello: world, foo: bar, baz: taco})
writer.end()


I like how easy this is. However, this always creates a new file. How could I append something to this file? Could I even use the same library?


More From » node.js

 Answers
38

Actually, fs.createWriteStream function decides how to open 'out.csv'



In your case, you can open this file for adding by using a flag:



writer.pipe(fs.createWriteStream('out.csv', {flags: 'a'}))


Here are the docs for this function and flags.


[#59828] Wednesday, November 30, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rickjordond

Total Points: 100
Total Questions: 105
Total Answers: 90

Location: Sweden
Member since Mon, May 8, 2023
1 Year ago
;