I am writing a simple server backend using NodeJS. On startup I create a directory on the file system as a location to store files permanently. However I noticed that the user is able to delete that storage folder while the server is running which is a behaviour I want to prevent. I dont assume users to delete that folder but I still want to handle that case simply by not allowing them to delete said folder. Trying to delete that folder while the server is running should fail with the common message that the ressource is currently used by a process similar to how you simply cannot delete files/folders used by other programs.
However I was not able to achieve such a behaviour with nodejs.
I tried to change the ownership of the folder using fs.chmod(..., "0700")
which unfortunately did not work as well as fs.chown
, however I was unsure which user id and group id I should use because something like $proccess.getuid()$ is not available on windows.
I also tried to open the folder using fs.opendir
and simply never close it (expect on server shutdown) but that also did not work.