Instructions for the fs.chmod method in node.js

  • 2020-05-07 19:11:37
  • OfStack

method description:

This method overwrites a file asynchronously.

The callback after the operation is completed receives only one parameter, and abnormal information may occur.

syntax:

fs.chmod(path, mode, callback)

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

receive parameters:

1. path               file path

2. mode           read and write permissions (e.g. 777)

3. callback   callback

example:


var fs = require('fs'),
 oldFilename = "./processId.txt",
 newFilename = "./processIdOld.txt";
fs.chmod(oldFilename, 777, function (err) {
 fs.rename(oldFilename, newFilename, function (err) {
  fs.lstat(newFilename, function (err, stats) {
   var isSymLink = stats.isSymbolicLink();
  });
 });
});

source code:


fs.chmod = function(path, mode, callback) {
  callback = makeCallback(callback);
  if (!nullCheck(path, callback)) return;
  binding.chmod(pathModule._makeLong(path),
                modeNum(mode),
                callback);
};


Related articles: