I'm building an app with express and mongodb. My app.js file has become pretty huge due to all the schemas and models being in it, along with the routes. Any suggestions where to define my schemas and models to prevent all the code ending up in one giant file?
You can dynamically insert your routes, models and schemas.
For example:
var routes = require('./routes');
In the Express config session you can do something like:
app.use(app.router);
And define your routes in the following fashion:
app.get('/', routes.index); // main page
Then, under routes/index.js you actually define what 'routes.index' does:
exports.index = function(req, res) {
res.render('index.html');
//or do whatever else you want
};
Check these articles out for further info: http://jordanhoff.com/post/22602013678/dynamic-express-routing
Good luck