Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda