title: Express and Mysql2 returning results from db query
body: <p>I am trying to return the results (an array of json objects) from my get_salt_and_hash() function. I then want to use the results in another function. (In this case the length of the results array is one.)</p>
  <p>However, after calling the get_salt_and_hash() in my other function, when I try to print the object I get undefined. I am unsure as to why, since console.log(results) in the original function works. Could someone help me out.</p>
  <pre><code>const get_salt_and_hash = (email) =&gt; {
  const query = `SELECT p_salt, p_hash FROM USERS_TABLE WHERE email= &quot;${email}&quot;`;
  db.query(query, (err, results) =&gt; {
      if (!err) {
          console.log(results);
          return results[0];
      } else {
          throw err
      }
  })}
  
  
  const verify_user = (email, password) =&gt; {
  
  let result_obj = get_salt_and_hash(email);
  console.log(result_obj);
  // const p_hash = result_obj['p_hash'];
  // const p_salt = result_obj['p_salt']
  </code></pre>
  <p>}</p>
  <p>I suspect it has something to do with asynchronous code, since it takes time for the db query to be made, but I pretty much no nothing about async javascript, so I thought it would be better to ask others.</p>
  <p>Thanks in advance!</p>