title: sending multiple JSON Objects lists in node js
body: <p>I am new to node.js can anyone tell me how to send multiple database rows using res.send() method ?in above code i fetch multiple rows from database but when i put those data into res.send() it doesn't working on for loop and gives me error like " throw err; // Rethrow non-MySQL errors
   ^</p>
  
  <p><strong>Can't set headers after they are sent."</strong></p>
  
  <p>app.post('/getUserList.htm',function(req,res){</p>
  
  <pre><code>console.log("Controller called..");
  
  var Obj=req.body.json;
  var data=JSON.parse(Obj);
  console.log("Json is: " + data[0].username);
  var query="SELECT * FROM app_user";
  connect.connection.query(query,function(err,rows){
      if(err){
          console.log("Error is: "+err);
      }else{
          var jsonObject={};
          var key = 'detail';
          jsonObject[key] = [];
          for (var i = 0; i &lt; rows.length; i++) { 
              console.log("UserName is :" + rows[i].SSO_ID);
              var details={
                  "username":rows[i].SSO_ID,
                  "PhoneNO" :rows[i].Wallet_Number
          };
              jsonObject[key].push(details);
              //JSON.stringify(jsonObject);
              console.log("JSON IS: " + jsonObject[key].userName);
              res.send({
              "data" :{   
          }
          }); 
          }
  
      }
  });
  </code></pre>
  
  <p>});</p>