title: Updating JSON file using JQuery to perform AJAX call nodejs
body: <p>I want to add a new user to a json file by using the user input in a form 
  I am able to upload the information to a txt file using the code below but I do not know how to do this using json, any help thank you</p>
  
  <p>ejs file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt; users &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;h1&gt;Users&lt;/h1&gt;
    &lt;% include templates/header.ejs %&gt;
  
    &lt;form action="http://127.0.0.1:3000/users" id="new" method="post" enctype='application/json'&gt;
      &lt;div id="form"&gt;
        &lt;label for="lname"&gt;Last Name&lt;/label&gt; &lt;input type="text"  id="lname" name="lname"&gt;
  
        &lt;label for="fname"&gt;First Name&lt;/label&gt;&lt;input type="text"id="fname"name="fname"&gt;
  
        &lt;label for="id"&gt;ID&lt;/label&gt;&lt;input type="text"id="id"name="id"&gt;
  
        &lt;button type="submit" id= "submit" value="Submit" &gt;Submit&lt;/button&gt;
  
   &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>user.js file:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var fs = require("fs");
  
  router.get('/', function(req, res, next) {
    res.render('users');
  });
  
  
  //will send the user input
  router.post('/', function(req, res) {
  
    var first= req.body.fname;
    var last= req.body.lname;
    var id= req.body.id;
  
    filePath = __dirname + '/people.txt';
    fs.appendFile(filePath, JSON.stringify(first + "   " + last + "   "+ id ),   function () {
      res.end();
    });
  
  });
  
  router.get('/listUsers', function (req, res) {
    fs.readFile( __dirname + "/" + "users.json", 'utf8', function (err, data) {
  
      console.log( data );
      res.end( data );
    });
  })
  
  module.exports = router;
  </code></pre>