'How To Append Data In Json Fs.writeFile without updating

Hey i want to append data to my json file but its Acutally updating the old data please help me refine the code

'use strict';
const fs = require('fs');

function handleSubmit(event) {
    event.preventDefault();

    const data = new FormData(event.target);

    const value = Object.fromEntries(data.entries());
  
    fs.writeFileSync('file.json', JSON.stringify([value], null, 2));
}

const form = document.querySelector("form");
form.addEventListener("submit", handleSubmit);

file.json

{
  "server_name": "ooo1",
  "server_ver": "office",
  "server_type": "false"
}

what i want that

[
{
  "server_name": "ooo1",
  "server_ver": "office",
  "server_type": "false"
},
{
  "server_name": "ooo2",
  "server_ver": "office",
  "server_type": "false"
}
]

i want the data to append not update please help me with best possible ways to help me make my new open source project



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source