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

248
Views
What is the return type of a router function?

If I want to avoid lots of else blocks and deep indentations, what should be the return type if I want to exit a router function explictly?

app.get("/xx", function(req, res) {
   if (c1) {
      res.render("c1");
      return ??;
   }
   if (c2) {
      res.render("c2");
      return ??;
   }
   res.render("default");
})
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

It doesn't really matter. This is an asynchronous function, and nobody's going to use this return value, so you can just return undefined:

res.render(...);
return;

As it doesn't matter, you can also write:

return res.render(...);

But I think it looks more readable in two lines.

about 4 years ago · Santiago Trujillo Report

0

Instead of res.render() you should be using res.send(), as it will terminate the response stream with the output sent.

about 4 years ago · Santiago Trujillo 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!