title: How to get app in router files (in Node/Express app)
body: <p>My app.js looks like this:</p>
  
  <pre><code>app = express();
  setup.configure(app);
  //...more stuff (e.g. database setup, middleware definition, etc.)...
  var api = require('./routes/api');
  app.use('/api', api);
  module.exports = app;
  </code></pre>
  
  <p>In the routes/api.js, I then have routes with middleware like this:</p>
  
  <pre><code>router.get('/myroute',
      app.sessionMW,
      function (req, res, next) {
          //...
      });
  </code></pre>
  
  <p>JSLint flags an error because I declare the <code>app</code> variable as global.
  If I declare it with <code>var</code>, I get an error in the route because app is <code>undefined</code>. If I require the app in the routes file with <code>var app = require('../app')</code>, I get this error:</p>
  
  <blockquote>
    <p>Error: Route.get() requires callback functions but got a [object
    Undefined]</p>
  </blockquote>
  
  <p>I would like to properly define the app by doing</p>
  
  <pre><code>var app = express();
  </code></pre>
  
  <p>But how do I access the app in the routes file?</p>