Discord.js FS Module Broken?


#1

Error occurs when i try and write to a json file.

Im creating a mute command for my discord bot and im adding timed mutes and idk for to fix this error if it is an error on my part. i believe its not since it works when i run it off my computer but dosent work when i run it off glitch

Error:

/app/cmds/mute.js:53
if(err) throw err;
^
Error: EACCES: permission denied, open ‘…/mutes.json’

Mute.js Code: pastebin.com/YNHRu0Le

Mutes.json Code:

{}

Picture Of Directory: prntscr.com/gypwix


#2

Did you copy the error direct form the console? It looks like there is an extra period in the path. Although your example code looks OK so I’m not sure whats up with that. Depending on how the project is setup I think it might just be a path issue. Haven’t done much with discord bots myself but if you PM me an invite to your project (or just the edit link if it’s public) maybe I can take a look.


#3

It may help to specify __dirname in the path so that you’re sure you’re pointing relatively from the correct directory. It’d also be worth running the following command from the console (under Advanced Options from the top-left Project Info menu in the editor) ls -la, which will list the files and their permissions to make sure you have write permission on that file and they haven’t been changed accidentally somehow.


#4

Definitely the issue is .. /, which attempts to go one folder up.

The fs module always reads from the project root, not from the current file, so even if mutes.js is in a subfolder, it still needs to refer to . /mutes.json if that file is in the root folder.


Error on using fs to writeFile json