title: Promise middleware in node js callback functions how to use multiple then?
body: <p>Am a newby in node js, Am using <a href="https://www.npmjs.com/package/promise" rel="nofollow">Promise</a> middleware in node js.
  But I didn't find its documentation useful for me and unable to understand how to use two callbacks in one request or how should use multiple then.
  Please help me thanks.</p>
  
  <p><strong>Here is my code</strong> </p>
  
  <pre><code>//get application types
  var p1 = new Promise(function(resolve, reject) {
    console.log("in p1");
    var url = tURL+'applicationType/getAll'
    var args = {
      headers:{"AuthKey": req.session.name}
    };
    client.get(url, args, function(data,response) {
        console.log(data, "in get all app type req");
        if(data.status == "success"){
          return resolve(data);
        }
        else{
          reject ("unamble to get data!")
        }
    });
  });
  
  p1.then(function(data) {
    console.log(data.response.applicationType, "in p1 then", data)
    //load page after data
    res.render('app', {
      message: req.session.name,
      uName: "THE MECHANIC",
      applist: data.response.applicationType
    });
  },function(reason) {
    console.log(reason, "reason in not then"); // Error!
  });
  
  
  
  //get all application
  var p2 = new Promise(function(resolve, reject){
    console.log("in p2");
    var url = tURL+'applications'
    var args = {
      headers:{"AuthKey": req.session.name}
    };
    client.get(url, args, function(data,response) {
        console.log(data, "in get app req");
        if(data.status == "success"){
          return resolve(data);
        }
        else{
          reject ("unamble to get data!")
        }
    });
  });
  
  p2.then(function(data) {
    console.log(data.response, "in p2 then", data)
    //load page after data
    res.render('app', {
      appList: data.response
    });
  
  },function(reason) {
    console.log(reason, "reason in not p2"); // Error!
  });
  </code></pre>
  
  <p><strong>Solutions am looking for</strong>
  1. I have to send data on page after both request complete.
  2. How can I manage response in object and send it to page by using <code>render</code> or any alternative?</p>