I've read that fs.appendFile
doesn't return fd
(file descriptor) so it opens the file and even closes for you. But in the example below i get error
Error: EMFILE: too many open files, open
[...Array(10000)].forEach( function (item,index) {
fs.appendFile("append.txt", index+ "\n", function (err) {
if (err) console.log(err);
})});
Which i assume means that for every new append it opens same file over and over. However with stream everything is fine
var stream = fs.createWriteStream("append.txt", {flags:'a'});
[...Array(10000)].forEach( function (item,index) {
stream.write(index + "\n")});
So, why in first case appendFile is not closing the file after the operation?