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

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