File system write error: EACCES


#1

I am using glitch.com for my private project. I encountered a problem with the file system recently. I’m using fs.writeFile(…) to overwrite a .json file (code below). I’m getting EACCES error message due to permission issues (I assume). My code is written in “time_manipulation.js”

One thing I noticed is that only absolute path for fs.writeFile works (and gave me the error message); all relative path doesn’t do anything from what I see.

My fs code:

fs.writeFile("/timedroles.json", JSON.stringify(timedroles), function (err) {
console.log(“added role - fs writeFile”);
if (err)
return console.log(err);
});

To give a sense of how my file directory looks like, I have the following on the “root” directory (as package.json and other default files will give the context):

/
assets
package.json
server.js
time_manipulation.js
timedroles.json

This is the error message I see:
error_fs

Please let me know if any actions will help resolve my problem. My current guess is that I need some kind of “permission” to overwrite my timedroles.json file.

Thank you in advance


#2

Hey @Nameless9 this is expected behavior. The path /timedroles.json is actually a sibling of the path that your project files are in, which lives at /app. The project user doesn’t have access to files outside of the /app home directory, so if you want to write your file to your project’s home directory you’ll want to use /app/timedroles.json or the relative path timedroles.json (depending on where you’re executing it from).

Hope this helps. Happy Glitching!


#3

when I use the “/app/timedroles.json” or the relative path, it seems that the file is not being edited/updated. May I know what the problem is?


#4

That’s probably related to the fact that changes to files from the back end (like what you’re doing with fs) and not the editor aren’t automatically synced with the editor view. You have to execute refresh in the console to force a sync between the files on the backend and what the editor sees.


#5

ok thank you for letting me know.