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

108
Visualizações
Trying to make a redirect page

I am creating a new user and saving it in my DB as shown below:

const user= new User({
    username: userId,
    password: pass,
    nameOfUser: user_name,
    emailOfUser: user_email
);
user.save();

res.redirect("/redirectpage");
setTimeout(function(){
    res.redirect("/");
},5000);

After saving the user I am trying to create a countdown redirect page. It looks something like:

enter image description here

After this, counter (of 5 seconds) reaches 0, I intend to redirect the user to the login page which is the home route. I implemented this through setTimeout. But unfortunately my app crashes giving the following errors: (** Note: If i comment out res.redirect("/redirectpage"), no errors are shown)

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This code tries to redirect the user twice. First to /redirectpage and then again to /. You can't do this, because calling res.redirect() the first time finishes the request, so you can't send any more data like a second redirect. You can fix this by moving the redirect code to the client side javascript. This code should work:

setTimeout(function() {
    window.location.replace("[full redirect url]");
}, 5000);

Read this answer to learn more about redirecting from the client-side.

about 4 years ago · Juan Pablo Isaza 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