title: How to get the function return value and pass it in a socket.emit?
body: <p>I have a problem in passing the return value of my query.
  When I try to console.log the return value inside my function. It shows all the data but when I try to use <code>return</code> it doesn't pass the data it says <code>undefined</code>.</p>
  
  <p>Here's my code:</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>var express = require('express');
  var app = express();
  var mysql = require('mysql');
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  var port = process.env.PORT || 8000;
  
  var connection = mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: '',
      database: 'node'    
  });
  
  app.use(express.static(__dirname + '/public'));
  app.use('/bower_components', express.static(__dirname + '/bower_components'));
  
  app.get('/', function(req, res) {
      res.sendFile(__dirname + '/index.html');
  });
  
  connection.connect();
  
  function loadList() {
  
      connection.query('SELECT * FROM inventory', function(err, rows, fields){
  
          if(err) throw err;
          //console.log(rows); --this is ok
          return rows; //cant return the data
  
      });
  
  }
  
  io.on('connection', function(socket){
  
      console.log('A user is connected!!');
  
      var product_list = loadList(); //return no result
  
      socket.emit('inventory list', {list: product_list});
  
      socket.on('disconnect', function() {
          console.log('user disconnected!');
      });
  
  });
  
  http.listen(8000, function() {
      console.log('Listening on ' + port);
  });
  </code></pre>
  
  <p><strong>For my index.html</strong></p>
  
  <pre><code>&lt;script type="text/javascript" src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/bower_components/jquery/dist/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
      try {
          var socket = io.connect('http://127.0.0.1:8000');
          //console.log(socket);
      }catch(e) {
          console.log('ERROR OCURRED: ' + e);
      }
  
      if(socket !== undefined) {
          socket.on('inventory list', function(data){
              console.log(data.list); //undefined return
          });
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Can you help me with this?</p>