title: Nodejs with Mysql Database Return value
body: <p>I have the following code. I am relative new to nodejs &amp;js </p>
  
  <p>I want to get values in 1. log but i get undefined. 
  Only 2. log is outputed to the log.</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/9651046/nodejs-return-value-from-callback">nodeJS return value from callback</a> and
  <a href="https://github.com/felixge/node-mysql" rel="nofollow noreferrer">https://github.com/felixge/node-mysql</a> but there is no example about return value.</p>
  
  <p>I donot know how to use return statement with the given example in node-mysql page.</p>
  
  <pre>
  exports.location_internal = function (req, res) {
      var r = getExternalLocation(2);
          // 1. log  
      console.log(r);
      res.send( r);
  }
  
  var getExternalLocation = function (id) {
      pool.getConnection(function(err, connection){
        if(err) throw err;
  
        var response = {};
        connection.query( "select * from external_geo_units where geo_unit_id = "+id,  function(err, rows){
          if(err) throw err;
          response.data= rows;
                  // 2. log
          console.log(response);
          return  response;
        });
        connection.release();
      });
  
  };
  </pre>