title: how to set cookie before sending response node js (Sails)
body: <p>I am having a problem if the cookie will be set before the the response is being sent.
  like i want to set cookie for logged in user and then i want to send the response OK.</p>
  
  <pre><code>User.find({user:req.body.username,password:req.body.password})
    .exec(function(err,row){
    if(err){
      console.log(err);
      res.negotiate();
    }
    else if(row.length){
      res.cookie('user',{user:row[0].user,role:row[0].role},{
        signed:true,
        httpOnly:true,
        maxAge:1000*60*60*24*5
      });
      res.end('You are logged in successfully');
    }
    else{
      console.log('nothing executed');
      res.end('Not such a user');
    }
  });
  </code></pre>
  
  <p>is it sure that the <code>res.cookie()</code> will be executed before <code>res.end()</code></p>