1

The project I'm working on allows the user to choose where they want to locate the files we use and by default on Windows we set the main file in a folder in C:\Program Files.

Well when wanting to test for RW perms in their selected location or default directory using fs.access or fsPromises.access it's returning that there is no error. But when going to create a test directory using fs.mkdir it throws EPERM.

This will eventually be used to detect no permissions and elevate a command using SudoPrompt (would love to use a different module but this is the only one I've found that works cross-platform.)

Testing the perms using fs.access. Testing the perms using fsPromises.access.

Attempting to create a directory.

The terminal I tested in is just a regular command prompt with no elevation. Running Node Version v18.6.0

  • Ultimately, the most reliable way to test if you have enough privilege to create a sub-directory in a particular location is to actually try creating one and then verify that it's there (and then clean it up when done). – jfriend00 Nov 29 '22 at 00:58

0 Answers0