given a RESTful web service that allows different users to post different articles
For defining the GET function on the server-sidem
i suppose there should be async functions like list, getTopViewed, getTopFavorite etc functions on the server-side
is the following correct then?
exports.get = function(req, res) {
db.articles.list(function etc)
db.articles.getTopViewed(function etc)
db.articles.getTopFavorite(function etc)
}
NOTE: where list, getTopViewed and getTopFavorite are defined in another JavaScript file
In another JS file:
exports.list = function(callback){
// acts as async callback
var result = ArticleModel.find({}, function(err, articles){
callback(null, articles)
});
return result;
}
I recommend using something like Connect or Express. It has a router that makes this a bit easier. Setup and usage look something like this:
Here’s a link to the docs for Express’ router: Application Routing