• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

46
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 2 months 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 2 months 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 2 months ago · Santiago Trujillo Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.