title: Append text to existing json file node.js
body: <p>I'm trying to add a new text to an existing json file, I tried writeFileSync and appendFileSync however the text added doesn't format as json even when i use JSON.stringify.</p>
  
  <pre><code>const fs = require('fs');
  
  fs.readFile("test.json", (err, data) =&gt; {
    if( err) throw err;
  
    var data = JSON.parse(data);
    console.log(data);
  });
  
  var student = {
    age: "23"
  };
  
  fs.appendFileSync("test.json", "age: 23");
  // var writeData = fs.writeFileSync("test.json", JSON.stringify(student));
  </code></pre>
  
  <p>My json file</p>
  
  <pre><code>{ name: "kevin" }
  </code></pre>
  
  <p>Append turns out like this, {name: "kevin"}age: "23"
  and writeFileSync turns out like {name: "kevin"}{age: "23"}</p>
  
  <p>What I want is to continuously add text to my json file like so</p>
  
  <pre><code>{
    name: "kevin",
    age: "23"
  }
  </code></pre>