Home > Articles > Web Development

  • Print
  • + Share This
Like this article? We recommend

Using close()

To close a file, simply use the close() method and pass in the file descriptor (obtained from the open() method):

var fs = require("fs");
var path = "c:\\Temp\\Test.txt";

fs.open(path, "w+", function(error, fd) {
     if (error) {
          console.error("open error:  " + error.message);
     } else {
          fs.close(fd, function(error) {
     if (error) {
          console.error("close error:  " + error.message);
     } else {
          console.log("File was closed!");
                      }
     });
   }
});
  • + Share This
  • 🔖 Save To Your Account