Wednesday, 26 April 2017

how get the req, res objects in the callbacks

I like to get the req, res, next objects outside the middleware function.

sample middleware - sample.js:

var app = express();
....
.....
....
var updateUserInput = {
   init:function(){
       get_data_from_db(params, function(){
           // want req, res here.
       })
   }
}

const processUserInput = function(req, res, next){
   updateUserInput.init();
}
module.exports = processUserInput;



via NSK

No comments:

Post a Comment