Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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");
})
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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.

over 4 years ago · Santiago Trujillo Denunciar

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda