title: Proper way to organize myapp/routes/*
body: <p>Using latest stable node.js and express from npm, I've created my first express project.</p>
  
  <p>The default generated app defines routes/index.js, which contains a single route that renders the default index view.</p>
  
  <p>I immediately assumed I could add other .js files to the routes/ folder and they would be included. This didn't pan out. Only routes/index.js is ever included. Adding additional routes to routes/index.js works fine.</p>
  
  <p><strong>What is the proper way to define and organize Express routes, following the structure provided by the express project generator?</strong></p>
  
  <hr>
  
  <p>The answer, paraphrasing the article at DailyJS:</p>
  
  <p>Given the following routes:</p>
  
  <pre><code>app.get('/', function() {});
  app.get('/users', function() {});
  app.get('/users/:id', function() {});
  </code></pre>
  
  <p>... Create the following files:</p>
  
  <pre><code>routes/
  ├── index.js
  ├── main.js
  └── users.js
  </code></pre>
  
  <p>Then, inside of routes/index.js:</p>
  
  <pre><code>require('./main');
  require('./users');
  </code></pre>
  
  <p><strong>For each new group of related routes, create a new file in routes/ and require() it from routes/index.js. Use main.js for routes that don't really fit in the other files.</strong></p>