Wednesday, 18 September 2013

nodejs querying data and code organization

nodejs querying data and code organization

Just started to learn nodejs, pretty new to js as well, and looked around
for best practices and came across this:
http://stackoverflow.com/a/15572522/1203349
I'm working on an app using this structure. He recommended putting the db
calls in corresponding model/model.js files.
E.g.
Using his sample, suppose I want a complete listing of blogs.
In routes/blog/index.js, should I do something like:
var Model = require('../../models');
module.exports = function(app){
app.get('/blog', function(req,res){
//what now? function calls into Model? how?
//also, why doesn't Model.blogModel.find({}, function(err, blogs){
//work with blogs
//}; work? I'm getting a ReferenceError: blogModel is not defined.
});
}
and in models/blog.js,
....
exports.<every function for crud>?
example implementation would be greatly appreciated.

No comments:

Post a Comment