Instructions for the fs.close method in node.js

  • 2020-05-05 10:55:57
  • OfStack

method description:

Close the file asynchronously.

syntax:


fs.close(fd, [callback(err)])

Since this method belongs to the fs module, it is necessary to introduce the fs module (var fs= require(" fs "))

before using it

receive parameters:

fd                             open

callback                 callback

example:


var fs = require('fs');
fs.open('/path/demo1.txt', 'a', function (err, fd) {
  if (err) {
    throw err;
  }
  fs.futimes(fd, 1388648322, 1388648322, function (err) {
    if (err) {
      throw err;
    }
    console.log('futimes complete');
    fs.close(fd, function () {
      console.log('Done');
    });
  });
});

source code:

[code]
fs.close = function(fd, callback) {
  binding.close(fd, makeCallback(callback));
};
[code]


Related articles: