Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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;
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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);
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!