I
I
irdaxirdaxirdax2020-07-01 17:53:35
JavaScript
irdaxirdaxirdax, 2020-07-01 17:53:35

Add element to json (Node.js)?

Hello.

In the node.js script, you need to make sure that users.json is added:

{
  "user#1111":{
    "coins": 100
    "steam_account": "steam11111"
    "socialclub": "user111111"
  }
}

How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2020-07-01
@irdaxirdaxirdax

as I understand it, you have an array of users in the users.json file,
if you connect it via const users = require("users.json") you will have a js object in the variable,
in your case an array of users, then you do users.push(user)
then write json through fs writeFile (don't forget to serialize the object through JSON.stringify(users)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question