Reputation: 20590
http://nodejs.org/api/fs.html#fs_fs_appendfile_filename_data_options_callback
Does fs.appendFile keeps a link to the file open so appends are faster? (rather than open/close each write)
What is the fastest way to write to a CSV file. I have using appendfile to write new lines to a CSV file. Would a write stream be faster? (if appendfile opens the file each time)
Note: I am actually writing about 20GB of CSV
Follow up: I can confirm that createWriteStream is much faster than appendFile
Upvotes: 6
Views: 2726
Reputation: 12265
fs.appendFile
is a convenience function.
If performance is important to you, you should use fs.createWriteStream
instead.
Upvotes: 4
Reputation: 5174
It looks like fs.appendFile
closes the file when it's finished writing each chunk.
https://github.com/joyent/node/blob/master/lib/fs.js#L907
So a stream is probably going to be faster. However, it will probably only make a difference if you're writing a significant number of CSV files.
Upvotes: 5