title: Returning SQL query results as a variable in node.js
body: <p>I'm trying to grab the results of an SQL query in order to use it elsewhere in my code, but I just can't figure out how to get them out. I have nested functions so I tried to get it out through two calls of return, but what comes out isn't valid.</p>
  
  <pre><code>var users = getUsers();
  
  
  function getUsers(req, res){
    dbConnect(req,res);
    return connection.query('SELECT * FROM USERS', function selectAll(err, rows, fields) {
      if (err) {
          throw err;
      }
      for (var i in rows) {
          console.log(rows[i]);
      }
      return rows;
      dbClose(req,res);
    })
  }
  </code></pre>
  
  <p>What's wrong here?</p>