Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda