title: How to properly access the app variable set by express in a node.js app?
body: <p>I'm building a node.js server and my folder structure looks like this:</p>
  
  <ul>
  <li>server.js</li>
  <li>app/routes.js</li>
  <li>app/routes/users.js</li>
  </ul>
  
  <p>My problem is that i'm not sure how can i use the <code>app</code> variable inside the users.js file. Do i have to require and setup express again in this file or is there a better/easier way to do it? Here is my sample code(just the bare minimum to understand my problem):</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>// Include our packages in our main server file
  var express     = require('express');
  var stormpath   = require('express-stormpath');
  var app         = express();
  
  // Init Stormpath for user management and authentication
  app.use(stormpath.init(app));
  
  // Load routes
  require('./app/routes')(app);
  
  // Start the server
  app.listen(process.env.PORT);
  
  // Stormpath will let you know when it's ready to start authenticating users.
  app.on('stormpath.ready', function () {
    console.log('Your server is running on port ' + port + '.');
  });
  </code></pre>
  
  <p><strong>app/routes.js</strong></p>
  
  <pre><code>// Import dependencies
  const express   = require('express');
  const stormpath = require('express-stormpath');
  
  // Export the routes for our app to use
  module.exports = function(app) {
    // Create API group routes
    const apiRoutes = express.Router();
  
    // User management: get users, invite users, view user profile
    var UsersRoute = require('./routes/users');
    apiRoutes.get('/memberinfo', stormpath.loginRequired, UsersRoute.memberInfo);
  
    // Set url for API group routes
    app.use('/', apiRoutes);
  };
  </code></pre>
  
  <p><strong>app/routes/users.js</strong></p>
  
  <pre><code>// Protected route test
  module.exports.memberInfo = function(req, res){
    //how do i access the "app" here?
      res.status(200).send({ user: req.user });
  }
  </code></pre>