title: Node.js controllers
body: <p>Im currently very new to Node.js - Express framework and Im trying to emulate a MVC pattern, so far I got this</p>
  
  <p>app.js </p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('static-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var http = require('http');
  
  var app = module.exports = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  app.set('port', process.env.PORT || 3000);
  
  app.use(favicon());
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded());
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  require('./routes');
  
  /// catch 404 and forwarding to error handler
  app.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
  });
  
  /// error handlers
  
  // development error handler
  // will print stacktrace
  if (app.get('env') === 'development') {
      app.use(function(err, req, res, next) {
          res.status(err.status || 500);
          res.render('error', {
              message: err.message,
              error: err
          });
      });
  }
  
  // production error handler
  // no stacktraces leaked to user
  app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
          message: err.message,
          error: {}
      });
  });
  
  http.createServer(app).listen(app.get('port'), function() {
      console.log("Running server");
  });
  </code></pre>
  
  <p>Just a normal app.js generated with the express generator with some modifications, now my routes/index.js</p>
  
  <pre><code>app = require('../app');
  
  app.get('/test', function(req, res) {
      require('./controllers/test.js');
      test();
  }); 
  
  app.get('/', function(req, res) {
      res.send('yankevf');
  }); 
  </code></pre>
  
  <p>As you can see on route /test if looks for module /controllers/test.js but since theres no actual module it wont work..</p>
  
  <p>How can I include a file that is inside the folder controllers? since my server keeps searching inside node_modules</p>