title: node.js/express js interaction between model and controller
body: <p>I am new to node.js so please bear with me.</p>
  
  <p>I am wondering what is the proper way to pass the model to the controller in node.  I sort of having it working but when I call a method from the model in my controller what I have returning from the model is 'undefined' and I am not sure why.  My connection to the DB is fine.  Take a look at my files and see my comments in all caps.</p>
  
  <p>routes.js</p>
  
  <pre><code>module.exports = function(app, dbConnection) {
   var theIndexModel = require('../models/index.server.models')(dbConnection);
   var index = require('../controllers/index.server.controller')(theIndexModel);
  
   app.get('/', index.homePage);
  };
  </code></pre>
  
  <p>models.js</p>
  
  <pre><code>function IndexModel(dbConnection) {
  
    modelMethods = {};
  
    modelMethods.getAllUsers = function(req, res) {
        var query = "SELECT * FROM `users`";
        dbConnection.query(query, function(err, rows, fields) {
          return rows; //NOT RETURNING ANYTHING WHEN I CALL FROM CONTOLLER!!
        });
    };
  
   return modelMethods;
  }
  
  module.exports = IndexModel;
  </code></pre>
  
  <p>controller.js</p>
  
  <pre><code>function IndexController(theIndexModel) {
    controllerMethods = {};
    controllerMethods.homePage = function(req, res) {
      console.log(theIndexModel.getAllUsers()); //UNDEFINED HERE, WHEN I SHOULD BE GETTING USERS FROM THE DB
      res.render('index', {
          title: 'hello'
      });
    };
  
  
  // Return the object that holds the methods.
  return controllerMethods;
  }
  
  module.exports = IndexController;
  </code></pre>
  
  <p>What am I doing wrong?  Thanks in advance. </p>