Unix uses POSIX permissions but Windows is based on a combination of:
- file attributes
like
readonly,hiddenandsystem.winattrandhidefilecan be used to manipulate those. - ACLs (also called NTFS permissions or just "file permissions").
- share permissions.
Node.js does not support Windows permissions.
fs.chmod(),
fs.stat()'s
mode,
fs.access(),
fs.open()'s
mode,
fs.mkdir()'s
options.mode and
process.umask()
only work on Unix with some minor exceptions:
fs.access()F_OKworks.fs.access()W_OKchecks thereadonlyfile attribute on Windows. This is quite limited as it does not check other file attributes nor ACLs.- The
readonlyfile attribute is checked on Windows when thewritePOSIX permission is missing for any user class (user,grouporothers).
On the other hand
fs.open()
works correctly on Windows where
flags are being
translated to Windows-specific file attributes and permissions.
On Windows, to execute files their extension must be listed in the environment
variable
PATHEXT.
Directories can be locked
on Windows. Erasing or removing them will fail. This can be solved by retrying
few milliseconds later using the
maxRetries option of fs.rm(),
graceful-fs or
rimraf.
Finally
fs.lchmod()
is only available on Mac.
File permissions are not cross-platform in Node.js.