Instructions for the fs.chown method in node.js
- 2020-05-07 19:09:46
- OfStack
method description:
Change file ownership.
syntax:
fs.chown(path, uid, gid, [callback(err)])
As this method belongs to fs module, fs module needs to be introduced before use (var fs= require(" fs ")).
receive parameters:
path directory path
uid user ID
gid group identity
callback callback, passing the exception parameter err
example:
fs.chown('content.txt', uid, gid, function(err){
if(err){
console.log(err);
}else{
console.log("change done");
}
})
source code:
fs.chown = function(path, uid, gid, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.chown(pathModule._makeLong(path), uid, gid, callback);
};