title: Sequential execution in node.js
body: <p>I have code like </p>
  
  <pre><code>common.findOne('list', {'listId': parseInt(request.params. istId)}, function(err, result){       
    if(err) {
      console.log(err);
    }
    else {
      var tArr = new Array();               
      if(result.tasks) {
        var tasks = result.tasks;
        for(var i in tasks) {
          console.log(tasks[i]);
          common.findOne('tasks', {'taskId':parseInt(tasks[i])}, function(err,res){
            tArr[i]  = res;       
            console.log(res);                     
          });                       
        }
        console.log(tArr);
      }               
      return response.send(result); 
    }
  });
  </code></pre>
  
  <p>It is not executed sequentially in node.js so I get an empty array at the end of execution. Problem is it will first execute <code>console.log(tArr);</code> and then execute  </p>
  
  <pre><code>common.findOne('tasks',{'taskId':parseInt(tasks[i])},function(err,res){
        tArr[i]  = res;       
        console.log(res);                                         
  });                       
  </code></pre>
  
  <p>Is there any mistake in my code or any other way for doing this.
  Thanks! </p>