Method description:
This method overwrites the read and write permissions of the file in an asynchronous manner.
The callback after the operation is completed only receives one parameter, and exception information may appear.
grammar:
fs.chmod(path, mode, callback)
Since this method belongs to the fs module, it is necessary to introduce the fs module before use (var fs = require("fs") )
Receive parameters:
1. path file path
2. Mode read and write permissions (such as: 777)
3. callback callback
example:
The code copy is as follows:
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:
The code copy is as follows:
fs.chmod = function(path, mode, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.chmod(pathModule._makeLong(path),
modeNum(mode),
callback);
};