title: Sails JS - Nested .query method doesn't run sequence
body: <p>I beginner in Sails JS. I try to make multiple .query("SELECT ... "). I have a problem when looks like it not run sequence. I will explain my problem, look to My snippet code :</p>
  
  <pre><code>var isSuccess = true;
  for(var loc = 0 ; loc &lt; decode.length ; loc++){
      Location.query('SELECT * FROM abc', function (err, res){
        if (err) {
          isSuccess = false;
          return res.json(200, {
            data: {
  
            },
            status: {
              id: 0,
              message: err.message
            }
          });
        } else {
          var validate = res.rows;
          sails.log(validate);
  
        secondQuery.query('SELECT * FROM def', function (err, seconResult) {
          if (err) {
            isSuccess = false;
            sails.log("Update is Success : "+isSuccess);
            return res.json(200, {
              data: {
  
              },
              status: {
                id: 0,
                message: err.message
              }
            });
          } else {
  
  
          }
        });
        }
      });
  
      if(isSuccess){
        return res.json(200, {
          data: {
  
          },
          status: {
            id: 1,
            message: "Successful",
            isSuccess: isSuccess
          }
        });
      }
    }
  </code></pre>
  
  <p>When i request the API via POST method and the result is :</p>
  
  <p>On Console Node JS Server :</p>
  
  <p>Update is Success : false
  So it means the request is failed and must be return status = 0 in postman</p>
  
  <p>But in the Postman, it show :</p>
  
  <pre><code>  data: {
  
          },
          status: {
            id: 1,
            message: "Successful",
            isSuccess: true
          }
  </code></pre>
  
  <p><strong>My Question :</strong></p>
  
  <p>Can anyone help me to explain why and how to make it a sequence process, not like "multi thread" ? (In my case, i need to use RAW query cause i will face with really complex query)</p>
  
  <p>Thank you. </p>