title: Express.js MVC structure : "Route.get() requires callback" error
body: <p>I want to be able to access my ensureAuthenticated function (it lives in app.js) from a router and controller file.</p>
  
  <p>app.js -> Application main page</p>
  
  <p>feed.js -> Feed router, nothing happens here. Just URL's.</p>
  
  <p>feedController.js -> Application logic is handled here. Adding, deleting, editing posts, etc.</p>
  
  <p>app.js</p>
  
  <pre><code>exports.ensureAuthenticated = function (req, res, next) {
      next(); // does nothing atm
  };
  </code></pre>
  
  <p>feed.js (just a router)</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var jwt = require('jsonwebtoken');
  var auth = require('../../app').ensureAuthenticated;
  
  var feedController = require('../../controllers/frontend/feed/feedController');
  
  router.get('/feedtest', auth, feedController.index);
  module.exports = router;
  </code></pre>
  
  <p>If I move ensureAuthenticated function from app.js to feed.js, it works. </p>
  
  <p>feedController.js</p>
  
  <pre><code>exports.index = function (req, res) {
      res.sendStatus(req.id);
  };
  </code></pre>
  
  <p>Error</p>
  
  <blockquote>
    <p>Error: Route.get() requires callback functions but got a [object
    Undefined]</p>
  </blockquote>