Can anyone explain me flow of execution of this code and how...
//router file
/* GET home page. */
Class.getClasses(function(err,classes){
res.render('classes/index', { classes: classes });
},3);
//model
//fetch all classes
module.exports.getClasses = function(callback,limit){
Class.find(callback).limit(limit);
}
You're not familiar with the concept of callbacks, I take it? The logic here is simple. You have your handler
The rest of your code says "go find me some classes. When you do, call this function". And so you call
Class.getClasses
which callsClass.find
which will invoke your handler when it's done.