Error on using fs to writeFile json


#1

There was a error when trying to write new data in a json file using fs , I think the file is read only , how to fix that issue
``

```const db = require("…/util/pikabot.json");
const servers = require("…/util/servers.json");
const users = require("…/util/users.json");
const { RichEmbed } = require(‘discord.js’);
const { writeFile } = require(“fs”);

exports.run = (client, message, args) => {
let user = users[message.author.id];
if (user.registered) return message.reply(“You are already registered.”);
let curr = db.defaultCurrencySign;
if (message.channel.type !== “dm”) {
let serverData = servers[message.guild.id];
if (servers) {
if (servers.currency !== “”) curr = servers.currency;
}
}
user.registered = true;
user.money += 100;
message.reply(“Registered " + message.author.tag + " and added 100 " + curr + " to account.”);
writeFile(’…/util/users.json’, JSON.stringify(users), (err) => {
if (err) console.error(err);
});
}```!!


#2

Make sure the path to your file is correct. A similar issue was opened recently and this answer helped them to resolve it: Discord.js FS Module Broken?


#3

The path is correct and I already read that Screenshot_2017-10-30-19-36-52-2
But the issue isn’t being fixed how to change permission of the file and check that there is permission to write on file


#4

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. But the error ENOENT means that the path is invalid.


#5

I have this


#6

As suggested before, I’d address the incorrect path you’re using.


#7

What I don’t get what you replied ?


#8

The first link I provided had the answer, but you can also use the absolute path /app/util/users.json instead of a relative one.


#9

It worked thanks for the help You’re really helpful​:+1::sparkling_heart: