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;
You should be able to pass those into the init function right away:
var updateUserInput = {
init:function(req,res,next){
get_data_from_db(params, function(){
// You will have req and res available here
// finish processing and call next()
})
}
}
const processUserInput = function(req, res, next){
updateUserInput.init(req,res,next);
}