Instructions for the fs.fchmod method in node.js

  • 2020-05-07 19:09:58
  • OfStack

method description:

Change file permissions (file descriptors).

syntax:


fs.fchmod(fd, mode, [callback(err)])

As this method belongs to fs module, fs module needs to be introduced before use (var fs= require(" fs ")).

receive parameters:

fd                           file descriptor

mode                 file permissions

callback           callback, passing the exception parameter err

example:


fs.open('content.txt', 'a', function (err, fd) {
  if (err) {
    throw err;
  }
  fs.fchmod(fd, 0777, function(err){
 if (err) {
      throw err;
    }
 console.log('fchmod complete');
    fs.close(fd, function () {
      console.log('Done');
    });
  })
});

source code:


fs.fchmod = function(fd, mode, callback) {
  binding.fchmod(fd, modeNum(mode), makeCallback(callback));
};


Related articles: