title: Node.js: require() and MODULE_NOT_FOUND
body: <p>As a learning exercise, I am attempting to build a router in Node.js, which is meant to be reusable.</p>
  <p>The file structure for my router looks like this:</p>
  <pre><code>/myProject
      app.js
      /routes
          index.js
          about.js
      /modules
          /router
              router.js
  </code></pre>
  <p>In <code>app.js</code>, I create a <code>router</code> object, and pass it the path to my routes folder:</p>
  <pre><code>var Router = require('./modules/router/router');
  var router = new Router('./routes');
  </code></pre>
  <p>Within the constructor of the router object, I load filenames into an array from the path passed to the object, and attempt to add them to an object as a module:</p>
  <pre><code>var fs = require('fs');
  var routes = {}
  var routesFolder;
  
  function Router(routesPath){
      this.routesFolder = routesPath;
      fs.readdir(this.routesFolder, this.loadRoutes);
  }
  
  Router.prototype.loadRoutes(err, files){
      for (var i=0;i&lt;files.length;i++){
          var c = files[i].split('.');
          if(c[1] === 'js'){
              try{
                  var t = require(routesFolder + '/' + c[0]);
                  routes['/' + c[0]] = t[c[0]];
              }
              catch(err){
                  console.log('Error parsing file: ' + files[i];
                  console.log(err);
              }
          }
      }
  }
  </code></pre>
  <p>My <code>index.js</code> and <code>about.js</code> files look like this:</p>
  <pre><code>exports.index = function(req, res){
      // Some code here
  }
  </code></pre>
  <p>I run <code>node app.js</code>, and I pass the router object <code>./routes</code> as the <code>route</code>'s path. The file names load just fine, but my console output is:</p>
  <pre><code>Error parsing: index.js
  { [Error: Cannot find module './routes/index'] code: 'MODULE_NOT_FOUND' }
  Error parsing: about.js
  { [Error: Cannot find module './routes/about'] code: 'MODULE_NOT_FOUND' }
  </code></pre>
  <p>I have attempted to alter my routes files in a few different ways:</p>
  <pre><code>module.exports = function(){...}
  module.exports.index = function(){...}
  </code></pre>
  <p>But this has no effect. From what I understand about <code>node</code> and <code>require</code>, this should work. I'm a bit of a novice, so please forgive me if the issue here is something silly.</p>