Cant save .json file

I have file users.json and i have to save it
Standard methods doesn’t work like using fs
How do i save my json file (pls write a code)

Ik that by typing “refresh” in console i can save it but i need it in code

What do you mean by save? Download it to your computer? Does copying and pasting get the job done?

const fs = require('fs'); 
fs.writeFileSync('demofile.json', JSON.stringify({hello:'world'})); 

i use this in my projects, try it

I meant load data from file then change and save it back. .json file is located on glitch

Like editing the file?

1 Like

Yes. I need to save users datas and edit it when smth changes

Glitch autosaves.

How often does it saves?

whoopsie, didn’t know what u meant

try this package from the public npm registry

Should be whenever you edit.

I think OP is just talking about the editor.

oh sorry rocks

2 Likes

It isnt works or i make sth wrong

I just declarate var and save file in it
Then i use fs to save file but it isnt saves

You are editing the file from the online editor, right? Or are you editing the file from your code?

From my code

Oh, ok, can you share your code/project so I can have a look?

Anything in your logs?

No, nothing about it

I’m not a node expert, but the standard way to use fs is to declare it at the top of the script:

const fs = require('fs')

1 Like