Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check (Windows) folder permissions using node js

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..

like image 202
SELVA Avatar asked Oct 18 '25 21:10

SELVA


1 Answers

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
like image 57
Pointy Avatar answered Oct 21 '25 10:10

Pointy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!