title: return value in nodejs function
body: <p>I am new in nodejs, while I write a function, it's not working for return a value in function. I fetch result from mysql then return to function. I know the reason because nodejs default is async. How can I fix my problem? this my source code:</p>
  
  <pre><code>function getSlaveURL() {
  var sqlQuery = "SELECT url FROM `slave` WHERE `id`='2' LIMIT 1";
  var returnValue = "";
  db.query(sqlQuery, function (error, rows) {
      if (error) {
          returnValue = "";
      } else {
          returnValue = rows[0]['url'];
          console.log("in function result: " + returnValue);
      }
  });
  return returnValue;
  }
  console.log("out function result: " + getSlaveURL());
  </code></pre>
  
  <p>=> result:</p>
  
  <p>out function result:</p>
  
  <p>in function result: <a href="http://localhost/mynodejs_slave/" rel="nofollow noreferrer">http://localhost/mynodejs_slave/</a></p>
  
  <p>Please help me to fix this problem.
  Thank you!</p>