title: nodejs mysql queries showing only one records instead of all records in the database
body: <p>Am trying to retrieve all the database records from  a table called <strong>post</strong> using node js but the problem is that only one record is retrieved instead of all.
  In php I can use  <strong><code>while()</code></strong> loop to loop through the database record to get all data. </p>
  
  <p>Currently, I do not know how to neatly loop through the database in nodejs to get all the records from database. Some Stackoverflow scholars suggest using await/async method but i do not know to to implement it on the code below to make it work. can someone help me fix the issue.</p>
  
  <pre><code>var connection = require('./config');
  module.exports.getpost = function (req, res) {
     connection.query('SELECT * FROM posts', function (error, results, fields) {
  
          if (error) {
              console.log('error');
              res.json({
                  status : false,
                  message : 'there are some error with the query'
  
              });
          } else {
              var postid = results[0].id;
              var title = results[0].title;
              var content = results[0].content;
              var type = -1;
               console.log(title);
  
          // Checking user status
     connection.query('SELECT count(*) as cntStatus,type FROM like_table WHERE userid= ? and postid=?', [userid,postid], function (error, results, fields) {
           if (error) {
                      console.log('error');
                      res.json({
                          status : false,
                          message : 'there are some error with the query'
  
                      });
                  } else {
  
  
  
                      var total_count = results[0].cntStatus;
   if(total_count &gt; 0){
          type = results[0].type;
  
          }
  
  
  
                      var total_count = results[0].cntStatus;
                      var result = {
  
  
  
                          "id" : postid,
                          "title" : title,
                          "content" : content,
  "type" : type,
  "likes" : total_count
                      };
  
                      console.log('query okay');
                      res.json({
                          //data:results,
                          data : result
  
                      });
                  }
              });
          }
  
      });
  }
  </code></pre>