Current documentation here doesn't seem to mention any parameters governing the stream's behaviour with regards to whether file is re-created every time or just gets data appended.
Is there a way to create a writeStream which appends the data?
To append data to file in Node. js, use Node FS appendFile() function for asynchronous file operation or Node FS appendFileSync() function for synchronous file operation.
The first more Node. js normal way to append to a file is using a callback. It appends to a file asynchronously. If the file does not exist it will create the file and then append the string to it, a Buffer can also be used in place of a string as data.
The appendFile() method is used to asynchronously append new data in the existing file or if the file does not exist then the file is created first and after that given data is appended to it.
There is a createWriteStream method right below it.
fs.createWriteStream(path, [options]) Returns a new WriteStream object (See Writable Stream).
options is an object with the following defaults:
{ 'flags': 'a' , 'encoding': null , 'mode': 0666 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With