title: node.js - function w/ mysql query not working
body: <p>this is the main<br></p>
  
  <pre><code>9.js
  </code></pre>
  
  <p>i am sending the "connection" details to<br>
  <code>3.js</code> so it can be used in the function named 'oo'</p>
  
  <pre><code>var http = require('http');
  var mysql = require('mysql');
  
  var connection = mysql.createConnection({
      host     : '------------',
      user     : '2',
      password : '--------------',
      database : '1',
  });
  
  connection.connect();
  var server=http.createServer(function(req,res){
      res.writeHead(200,{'Content-Type': 'text/html; charset=utf-8'});
      var oo = require('/3.js');
      var ee = oo(connection);
      res.end(ee);
  }).listen(80);
  </code></pre>
  
  <p>this is the <code>3.js</code></p>
  
  <pre><code>function oo(connection) {
  
      var ss = 'SELECT * FROM 1_accounts order by ac_nu asc limit 5';
      connection.query(ss, function(err,res,fields){
      bb = JSON.stringify(res);
      });
      return bb;
  }
  module.exports = oo;
  </code></pre>
  
  <p>let's run :</p>
  
  <pre><code>root@11669:/# node 9.js
  /3.js:7
      return bb;
             ^
  
  ReferenceError: bb is not defined
      at oo (/3.js:7:9)
      at Server.&lt;anonymous&gt; (/9.js:20:11)
      at emitTwo (events.js:87:13)
      at Server.emit (events.js:172:7)
      at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:528:12)
      at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
  root@11669:/# 
  </code></pre>
  
  <p>it claims "bb" is not defined.<br>
  but it is defined in the function.</p>
  
  <p>i prefer not adding any "callback" things. trying to figure out the simplest way to get "bb" perhaps via "return" like regular normal function just like in php and so on..</p>