Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 3.04 KB

permissions.md

File metadata and controls

71 lines (56 loc) · 3.04 KB

🔒 Permissions

Core concepts

Unix uses POSIX permissions but Windows is based on a combination of:

  • file attributes like readonly, hidden and system. winattr and hidefile can be used to manipulate those.
  • ACLs (also called NTFS permissions or just "file permissions").
  • share permissions.

Lack of support

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_OK works.
  • fs.access() W_OK checks the readonly file attribute on Windows. This is quite limited as it does not check other file attributes nor ACLs.
  • The readonly file attribute is checked on Windows when the write POSIX permission is missing for any user class (user, group or others).

On the other hand fs.open() works correctly on Windows where flags are being translated to Windows-specific file attributes and permissions.

Other differences

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.

Summary

File permissions are not cross-platform in Node.js.


Next (🔒 Users)
Previous (🔒 Security)
Top