NodeJS: Does fs.appendFile keeps a link to the file open so appends are faster?

node.js

Solution

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.

Problem

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

Original source