I'm trying to modularize my node.js application (using express framework). The trouble I am having is when setting up my routes.
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?
My app.js
require('./routes.js').setRoutes(app);
My route.js
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
}
});
});