I need to store an array of URLs associated with number in json file. This is what I got so far:
json[message.guild.id] = {
songs: []
};
fs.readFile("./settings.json", "utf8", (err, data) => {
if (err) {
throw err;
} else {
json[message.guild.id] = JSON.parse(data);
}
});
json[message.guild.id].songs.push(url); // adding a new URL
fs.writeFile("./settings.json", JSON.stringify(json, null, 4), err => {
if (err) throw err;
});
And this does work, but if I try to save next URL it just overrides the existing one. What is wrong and how I can remove one of the saved URLs?