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)

1 Like

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

1 Like

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

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

i use this in my projects, try it

1 Like

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

1 Like

Like editing the file?

2 Likes

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

1 Like

Glitch autosaves.

1 Like

How often does it saves?

1 Like

whoopsie, didn’t know what u meant

try this package from the public npm registry

1 Like

Should be whenever you edit.

1 Like

I think OP is just talking about the editor.

1 Like

oh sorry rocks

3 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

1 Like

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