My code looks something like this:
router.route('/user')
.post(function(req, res, next){
queryDB(arg1, arg2, prepareRes)
})
.get(function(req, res, next){
queryDB(arg3, arg4, prepareRes)
});
var prepareRes = function(err, data){
if(err) next(err);
else{
req.data = data;
}
};
when i run this code i get the following error:
ReferenceError: next is not defined
or
ReferenceError: req is not defined
This happens because req and next ,are outside prepareRes scope.
How can get around this ERROR??
I don't want to have to duplicate the same lines of code in both routes and its not possible to use
route.all
in my case.