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

265
Views
(Express) Cómo pasar un valor de una función a otra en express.Router().get

Cómo puedo pasar valor de una función a otra en 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 answers
Answer question

0

Puedes usar res.locals para hacer eso

Un objeto que contiene variables locales de respuesta en el ámbito de la solicitud y, por lo tanto, disponible solo para las vistas representadas durante ese ciclo de solicitud/respuesta (si corresponde).

Entonces en tu caso

 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 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!