title: How do you modularize Node.JS w/Express
body: <p>I'm trying to modularize my node.js application (using express framework). The trouble I am having is when setting up my routes. </p>
  
  <p>I am no longer able to extract the data I send to the post. (req.body is undefined). This works okay if it is all in the same file. What am I doing wrong here, and what is the best way to modularize code in node.js?</p>
  
  <p>My app.js</p>
  
  <pre><code>require('./routes.js').setRoutes(app);
  </code></pre>
  
  <p>My route.js</p>
  
  <pre><code>exports.setRoutes = function(app){
  
    app.post('/ask', function(req, res, next){
      time = new Date();
  
      var newQuestion = {title: req.body.title, time: time.getTime(), vote:1};
      app.questions.push(newQuestion);
      res.render('index', {
        locals: {
          title: 'Questions',
          questions: app.questions
        }
      });
  });
  </code></pre>