Can't write to .JSON files

Hi, i got problem that whatever i try, i can’t write to .json files, it just does nothing. I’m making discord bot and i need to store muted users there. Test code:

if (command === “write”) {

   var fs = require('fs'); 
fs.writeFile('./mutes.json', 'Hello world!', (err) => {
if (err) throw err;

});
}

I have tried everything, but nothing seems to work, it also gives no error.

Hey @TimeCold, welcome to the Glitch Forums!

You’re probably running into the limitation that files edited on the backend (i.e. in code or in the console) don’t automatically sync with the editor. If you want to see those changes in the editor you need to run the refresh command in your project’s console (which you can reach by opening the Logs pane by clicking on the Logs button under your project’s name and then clicking on Console in the pane).

You can also put this in your code by using node’s child-process module.

If this file is going to change regularly then you may run into problems with those changes filling up your git repo, which can in turn fill up your project’s available disk space. To avoid that you’d need to add it to a gitignore file, but that will also keep it from showing up in the editor at all.

Hope this is helpful. Happy Glitching!

1 Like

Ohh, refresh command helped, even my old text files that i tried to create appeared, thanks :smiley:

1 Like