I need to know how to find the permission to write in a specified folder, using NodeJs. (for the current user).
I have tried with
fs.access(path,fs.W_OK,function(err){})
and
fs.accessSync(path,fs.W_OK).
But, i am facing a TypeError, "Object has no method access".
I can do,
var stats = fs.statSync(path);
and get the details of a particular folder. Is there any method to find write permissions using the stats Object?
Any other solution is also appreciatable.
Thanks in advance..
You can examine the "mode" property of the returned object. The access permissions are as per traditional Unix access permissions, in groups of 3 bits.
var mode = fs.statSync(path).mode;
var writePermissions = mode & 0x92; // 010010010
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With