title: Node.js returning result from MySQL query
body: <p>I have the following function that gets a hexcode from the database</p>
  
  <pre><code>function getColour(username, roomCount)
  {
      connection.query('SELECT hexcode FROM colours WHERE precedence = ?', [roomCount], function(err, result)
      {
          if (err) throw err;
          return result[0].hexcode;
      });
  }
  </code></pre>
  
  <p>My problem is that I am returning the result in the callback function but the getColour function doesn't return anything.  I want the getColour function to return the value of <code>result[0].hexcode</code>.  </p>
  
  <p>At the moment when I called getColour it doesn't return anything</p>
  
  <p>I've tried doing something like</p>
  
  <pre><code>function getColour(username, roomCount)
  {
      var colour = '';
      connection.query('SELECT hexcode FROM colours WHERE precedence = ?', [roomCount], function(err, result)
      {
          if (err) throw err;
          colour = result[0].hexcode;
      });
      return colour;
  }
  </code></pre>
  
  <p>but of course the SELECT query has finished by the time return the value in <code>colour</code></p>