title: Combine routes from multiple files in ExpressJS?
body: <p>What is the best way to <strong>combine</strong> routes from <strong>two</strong> files so Express Router will handle them at the <strong>same</strong> level?  I'm thinking of something like this:</p>
  
  <p><strong>Default Routes File</strong><br>
  This file would be generated and overwritten every time the generator runs:</p>
  
  <pre><code>var express     = require('express'),
      router      = express.Router(),
      custom      = require('./custom.routes');
  
  router.get('/', function (req, res) {
  });
  router.post('/', function (req, res) {
  });
  router.put('/', function (req, res) {
  });
  
  router.use('/', custom);
  
  module.exports = router;
  </code></pre>
  
  <p><strong>Custom Routes File</strong><br>
  This file would only be generated the first time and would never be overwritten.</p>
  
  <pre><code>var express = require('express'),
      router  = express.Router();
  
  router.post('/custom-method', function (req, res) {
  
  });
  
  module.exports = router;
  </code></pre>
  
  <p><strong>Parent Route File</strong><br>
  This file is generated and overwritten constantly.  It is responsible for providing the top level <code>api</code> route:</p>
  
  <pre><code>var express = require('express'),
      apiRouter  = express.Router();
  
  var widgetRouter = require('./widget.routes');
  apiRouter.use('/widgets', widgetRouter);
  
  var sprocketRouter = require('./sprocket.routes');
  apiRouter.use('/sprockets', sprocketRouter);
  
  module.exports = apiRouter;
  </code></pre>
  
  <p>The obvious goal is to allow the developer to customize the routes and know his work will be safe even when the generator is run again.</p>