I'm writing my first MEAN app... To be correct, currently it is a MEN :-) app, since it's only the server-side API by now...
I'd like to follow an MVC pattern (or MC, since I have no views).
I want to choose a correct structure for my app, and I'm trying to understand how to use routes, model and controllers... In particular, it's not clear to me how to use controllers...
The first question is this: how and where do I define my class methods?
Currently:
I define a 'model' in "models/person.js".
Then, I add (class) methods in the same model file, this way:
personSchema.method.save = function(callback) {
this.model('Person').savefind({ type: this.type }, callback);
}
module.exports = mongoose.model('Person', personSchema);
Then, in the routes ("routes/persons.js", for example), I require() the models I need, and implement the route methods.
If this is a correct and common approach, I do not understand how to use controllers... :-(
Maybe controllers are not needed in a server-side API exposing application?
Hope someone can shed some light on my MEAN understanding... :-)