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

150
Views
How to use one variable in two middlewares nodeJS

I am trying to use one variable in two middlewares but it says ( is not defined )

example:


//1st middleware

app.use((req, res, next) =>{
    contentType = req.headers['content-type'];
    if(contentType === 'application/x-www-form-urlencoded'){
        next();
    }
})

//2nd middleware

app.use({
)

this is just an example so kindly tell me how would I make ( contentType ) as an accessible variable from the 2nd middleware?

Thanks alot

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here you go, mate. basically, the expressJWT() function returns a middleware that takes 3 parameters, req, res, and next which is used to go to the next middleware, so what I did is that I used the parameters with expressJWT.

//1st middleware

app.use((req, res, next) =>{
    req.contentType = req.headers['content-type'];
    if(req.contentType === 'application/x-www-form-urlencoded'){
        next();
    }
})

//2nd middleware

app.use((req, res, next) => expressJWT({
    secret: jwk.expressJwtSecret({
        jwksUri: req.contentType
    }),
})(req, res, next))
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!