O
O
ojiekcahdp2021-02-04 20:52:39
Node.js
ojiekcahdp, 2021-02-04 20:52:39

How to push to json file?

There is a json file. I want to push into it

prize.push({
    id: my.Id
  })

But it doesn't work, there is a way
setInterval(async () => {
    fs.writeFileSync("./myJson.json", JSON.stringify(prize, null, "\t"))
  }, 500);

But this always updates the file, without the possibility of changing it, what can be replaced with this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Israfil22, 2021-02-04
@Israfil22

You can't use JSON in this way. It is a data representation format , not a storage format.
Use databases - SQLite, for example. This is a very lightweight database and does not require a lot of knowledge from you.
Even easier to interact with it can help any available ORM.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question