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

177
Views
¿Cuál es el tipo de retorno de una función de enrutador?

Si quiero evitar muchos bloques else y sangrías profundas, ¿cuál debería ser el tipo de retorno si quiero salir de una función de enrutador de forma explícita?

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

0

Realmente no importa. Esta es una función asíncrona, y nadie va a usar este valor de retorno, por lo que puede devolver undefined :

 res.render(...); return;

Como no importa, también puedes escribir:

 return res.render(...);

Pero creo que se ve más legible en dos líneas.

over 4 years ago · Santiago Trujillo Report

0

En lugar de res.render() , debe usar res.send() , ya que terminará el flujo de respuesta con la salida enviada.

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