I have the following code, which is a simplified example of what I am trying to do:
const fs = require('fs');
var stream = fs.createWriteStream('/tmp/file');
stream.once('open', function(fd) {
for (var i = 0; i < 100; i += 1) {
stream.write('' + i + "\n");
}
stream.end();
stream.close();
});
I can see that fd
is the file descriptor and I wanted to close it. I called fd.close()
, but that is not a method.
Two questions:
- Should I be closing it?
- How do I close it?
I saw some documentation on fs.close()
and fs.closeSync()
. Should I use that?
Thanks.