title: How would i add a key:value pair to a json list in node.js?
body: <p>I am using node.js, and i want to add the arguments from a command and the server id as a key:value pair into a json file like this:</p>
  <pre class="lang-js prettyprint-override"><code>{
  
      &quot;guildid&quot;: &quot;args&quot;,
      &quot;guildid2&quot;: &quot;args2&quot;,
  
  }
  </code></pre>
  <p>And the current code that i have is far from what i want, where this code:</p>
  <pre class="lang-js prettyprint-override"><code>const command = args.shift().toLowerCase();
  const args = message.content.slice(config.prefix.length).trim().split(' ');
  
  if (command === 'setup') {
  const guildid = message.guild.id
          const data = { 
              [guildid]: `${args}`
              }
          const groupname = JSON.stringify(data, null, 2);
          fs.writeFile('./groups.json', groupname,{flags: &quot;a&quot;}, finished);
          function finished(err) {
              message.channel.send(`Success! Your group, **${args}**, has been registered to **${message.guild.name}**`
              )}
  </code></pre>
  <p>Outputs what i want to the json file, but if i run the command again it just appends to the end:</p>
  <pre class="lang-js prettyprint-override"><code>{
    &quot;guildid&quot;: &quot;args&quot;
  }{
    &quot;guildid2&quot;: &quot;args2&quot;
  }
  </code></pre>
  <p>I understand now that using the a flag just appends to the end no matter what and const data is what is giving it the brackets, but i want to know how to be able to format it in the way i showed at the beginning. Apologies for any glaring errors i have made, this is one of my first times using javascript and node.js.</p>