Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create appending writeStream in Node.js

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?

like image 781
Art Avatar asked Oct 13 '10 23:10

Art


People also ask

How do you append data in node JS?

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.

How do I append one file to another in node JS?

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.

Which method is used to append file in Nodejs?

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.


1 Answers

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 } 
like image 178
Corey Hart Avatar answered Oct 02 '22 21:10

Corey Hart