title: Asynchronous function in express middleware
body: <p>I use express 4+ and i have a registration route that made and asynchroneous call before render the page. the code is below:</p>
  
  <pre><code>router.get('/registration' , (req , res)=&gt;{
    let query = new Parse.Query(Parse.Role);
    query.equalTo('public',true);
  
    query.find().then((rs)=&gt;{
      let roles = rs.map((r)=&gt;{
        return {'id':r.id , 'name':r.get('ui_name')}
      });
      res.render('registration/registration.njk' , {roles:roles});
    } , (error , code)=&gt;{
      res.send(new Error(500));
    })
  
  })
  </code></pre>
  
  <p>The problems is when i do that, all the middlewares are called twice and all sessions data and cookie  is removed. This cause problems because i can't fetch current user.</p>
  
  <p>How can i prevent this ?</p>