title: Sequelize does not return a value within a function
body: <p>I am using Sequelize to connect to Azure SQL database from Node.js. The sequelize query module is placed within a function, and the matched boolean variable is returned to the main script (app.js).</p>
  
  <p>Sequelize along with the function are part of (app_functions.js)</p>
  
  <p>The code snippets are pasted below:<br></p>
  
  <p><strong>app_functions.js</strong></p>
  
  <pre><code>function loginIds(email_id) {
    var is_matched = false;
  
    sequelize.query("SELECT emailid FROM user_data where emailid='" + email_id + "'", {
        type: sequelize.QueryTypes.SELECT
      })
      .then(result =&gt; {
        console.log(result);
        console.log('DB email id is: ' + result[0].emailid);
  
        if (result[0].emailid != '') {
          console.log('True block');
          is_matched = true;
        } else {
          is_matched = false;
        }
      })
  
    return is_matched;
  }
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>// Import app_functions.js
  var fs = require('fs');
  eval(fs.readFileSync('app_functions.js').toString());
  
  console.log("Matched value is: "+ loginIds('xyz@gmail.com'));
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Matched value is: false
  Executing (default): SELECT emailid FROM user_data where emailid='xyz@gmail.com'
  [ { emailid: 'xyz@gmail.com' } ]
  DB email id is: xyz@gmail.com
  True block
  </code></pre>
  
  <p>The function returns <code>false</code>, although the <code>True block</code>, inside <code>if</code> condition is executed.
  Also note that, the function returns the value first and then executes the definition.</p>
  
  <p><strong>How to return the correct <code>true</code> value from the function containing sequelize?</strong></p>