title: Node.js with express routing and sub routing
body: <p>I am playing with node.js and I don't quite understand why something I set up is working in one instance but if I make a slight change it will not work in another instance.</p>
  
  <p>in my app.js I have</p>
  
  <pre><code>app.use('/musicplayer',  require('./routes/music/index'));
  </code></pre>
  
  <p>in my music\index.js I have</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  router.use('/users', require('./users'));
  
  module.exports = router;
  </code></pre>
  
  <p>in my users.js I have this - <strong>working version</strong></p>
  
  <pre><code>var express = require('express');
  var usersRouter = express.Router();
  var sqllite3 = require('sqlite3').verbose();
  
  usersRouter.get('/login', function(req, res, next) {
      res.render('music/login', { title: 'Express' });
  });
  module.exports = usersRouter;
  </code></pre>
  
  <p>But I would like to encapsulate the routes I am defining into another function like this <strong>not working</strong> this just hangs the page.  </p>
  
  <p>Modified version of my users.js <strong>not working</strong> </p>
  
  <pre><code>var express = require('express');
  var usersRouter = express.Router();
  var sqllite3 = require('sqlite3').verbose();
  
  var router = function () {
      usersRouter.get('/login', function (req, res, next) {
          res.render('music/login', {title: 'Express'});
      });
      return usersRouter;
  }
  module.exports = router;
  </code></pre>
  
  <p>In the console I can see it comes in tries the get and nevers gets routed I see this "GET /musicplayer/users/login - - ms - -".  </p>
  
  <p>I have even put a console.log right before the return in the anonymous function I created to know it is getting in there and that I am hooking the pathways up right from the parent routes.  And I do hit that log action to the screen.</p>
  
  <p>Any help or tips would be appreciated:)</p>
  
  <p>PS in case you are wondering I am trying to separate out apps for different development work I want to play with.  So that is why I am doing the sub routing with musicplayer/index.js instead of just putting everything in the app.js for declaring of my main routes.</p>