Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
How to have req, res and pass additional variables? (NodeJS, Express)

I have an export module that gets a post_id and id of the current user to update something in my DB. Untill now this worked for me:

//call
const promise = authController.function(req.params.post_id, decoded.id);
promise.then(results => res.json(results));

exports.function = async (post_id, decoded) => {
    // doing the thing
}

Now I started using flash messages in case something is wrong to alert the user that I would use like this:

exports.function = async (post_id, decoded) => {
    // doing the thing
    if (error) {
       req.flash("flash", 'Your login has expired.'); // or something like that
       return res.redirect('back');
    }
}

So now I need to somehow pass my variables and have req, res in the same function. How can I do this properly?

// The best I could come up with?
const promise = authController.function(req.params.post_id, decoded.id);
exports.function = async (req, res, post_id, decoded)
{ // the thing }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda