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

269
Vistas
(Express)How to pass a value from function to another one in express.Router().get

How I can pass value from function to another one at router.get

router.get('/someurl', (req, res, next) => {
const token = req.headers.authorization.split(' ')[1] //jwtToken
const jwt = jwt.verify(
    token,
    jwtSecret
)
...do something to pass value to the next function
}, )
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use res.locals to do that

An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any).

So in your case

router.get(
  "/someurl",
  (req, res, next) => {
    const token = req.headers.authorization.split(" ")[1]; //jwtToken
    const jwt = jwt.verify(token, jwtSecret);
    // pass to res.locals so I can get it in next() middleware
    res.locals.token = token;
    next();
  },
  (req, res, next) => {
    // inside the next() middleware
    // get token from res.locals
    const previousToken = res.locals.token;
  }
);

about 4 years ago · Juan Pablo Isaza Denunciar
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