This is really a head scratcher...
I'm running Node 22.9.0 on a raspberry PI (Linux raspberrypi 6.1.21-v8+)
My script, which is run as root, can write a new file in the current directory and update that file just fine.
total 332 drwxr-xr-x 11 root root 4096 Feb 8 06:37 . drwxr-xr-x 4 root root 4096 Dec 20 07:24 .. ..... -rw-r--r-- 1 root root 1861 Feb 8 06:37 database.json (THE FILE) I have a event loop in the script that runs inside of setInterval. Inside that event loop, I receive the following error when trying to write to the file...
Error! Error: EACCES: permission denied, open 'database.json'
It seems that inside the loop, I lose access to the directory...
setInterval(() => { console.log(process.env.USER) // root fs.access("./database.json", fs.constants.W_OK, (err) => { if (err) { // am seeing this log!! console.error('Directory is not writable'); } }); }, 2000); Any ideas why I can write outside of setInterval, but not inside of setInterval?