I could not find much information in the documentation. Using fs
, is it possible that a stream opened with fs.createWriteStream
closes unexpectedly or stops writing to file before calling stream.end()
?
One scenario that comes to my mind is an error happens and the OS closes the stream. Is this possible, and in this case would fs
reopen the stream automatically?
I think we can use something along the lines of
let stream = fs.createWriteStream('file.log', {flags: 'a'});
stream.on('close', () => {
stream = fs.createWriteStream('file.log', {flags: 'a'});
});
But I wonder if this approach is prone to memory leaks or other issues. Thanks!