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

262
Views
(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 answers
Answer question

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