0

I am building a website for recording and viewing patients data. In server side, I am using Node.js+express and I am rendering the pages with ejs. I am able to transfer to data within the pages without issues. However,I am stuck with parsing the JSON data. In my code:

 // Get all patients in the system
    app.get('/patients', function (req, res, next) {
        console.log("ALL PATIENTS PAGE");
        getRequestCounter++;
        console.log("Processed Request Counter --> GET: " +  getRequestCounter + ", POST: " + postRequestCounter + ", PUT: " + putRequestCounter +", DELETE: " +deleteRequestCounter);
        Patient.find({},function(err, data){
            console.log("DATA IS HERE" + data);
            if(err) throw err;
            res.render("patients", {collection: data});
        });

        console.log('received GET request.');
    })

I am getting all the patients info from MongoDb and pass it to the patients.ejs page as raw data.

 <div class="middle">

  <h2> Patients Information</h2>
  <p> <%= collection%></p>

</div>

When I pass it the output is seem as follows: output

So, I would like to know an effective and nice way to parse the JSON data which will look beautiful in HTML. Thanks a lot!

obayral
  • 141
  • 3
  • 15

0 Answers0