title: Express.js returning multiple routes in a single exported router object returns incorrect route
body: <p>I am trying to utilize an MVC pattern for express. I am modularizing routes and trying to declare the express router in only the server entry file and nowhere else.</p>
  <p>My current issue is when exporting my <strong>appRoute</strong> function in my <strong>main routes file</strong> (see below), the first route (user route), returns users. I have another route called game that is exported in the same function but it still returns users instead of games.</p>
  <p>Both routes have a controller function called getAll that gets different data from different tables.</p>
  <p>If I try and visit the route: http://localhost:8000/user/getAll, it returns all users just fine.
  If I try and visit the route: http://localhost:8000/game/getAll, it still returns all users even when they're different routes...</p>
  <p>If I were to flip the order of users and games in the main routes file where game is first and user is second, users starts to return games. It's like the second route mimics the first route.</p>
  <p>This may be something simple, but any help I will appreciate.</p>
  <p>My code is as shown below</p>
  <p><strong>server entry point (index.js)</strong></p>
  <pre><code>const app = express();
  const router = express.Router();
  const bootstrap = require('./src/bootstrap');
  bootstrap(app, router);
  </code></pre>
  <p>I am passing on the app and router instance to my bootstrap file where all routes will be exported to.</p>
  <p><strong>bootstrap.js</strong> (this file gets all exported routes and uses them within the app)</p>
  <pre><code>const { appRoute } = require('./routes');
  
  module.exports = (app, router) =&gt; {
    return app.use('/', appRoute(router));
  };
  </code></pre>
  <p>I am passing on the router instance to my main routes file where all routes are exported from.</p>
  <p><strong>Main routes file</strong> (index.js): this file requires all routes and uses them within the router instance. I think this might be where my issue is but I am a little stuck on how I might fix it.</p>
  <pre><code>const { userRoute } = require('./userRoute');
  const { gameRoute } = require('./gameRoute');
  
  exports.appRoute = (router) =&gt; {
    router.use('/user', userRoute(router));
    router.use('/game', gameRoute(router));
    return router;
  };
  </code></pre>
  <p>Game route files (index.js): returns all users instead of games</p>
  <pre><code>const { gameController } = require('../../controllers');
  
  exports.gameRoute = (router) =&gt; {
    return router.get('/getAll', gameController.getAll);
  };
  </code></pre>
  <p>Any help is greatly appreciated. If there is any clarification needed please let me know.</p>