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

126
Views
Cuando estoy haciendo una solicitud POST en mi página de inicio de sesión

Recibo este error: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client cuando estoy ejecutando mi código ExpressJS.

Ayuda chicos, esta es mi primera pregunta sobre stackoverflow por cierto y realmente no sé cómo hacer preguntas :^)

Mi código:

 app.route("/") .get(function(req,res){ res.render("home"); }) app.route("/register") .get(function(req,res){ res.render("register"); }) .post(function(req,res){ bcrypt.hash(req.body.password, saltRounds, function(err, hash) { const newUser = new User({ email: req.body.username, password: hash }) newUser.save(function(err){ if (err){ console.log(err); } else { res.render("secrets"); } }); }); }); app.route("/login") .get(function(req,res){ res.render("login"); }) .post(function(req,res){ const username = req.body.username; const password = req.body.password; User.findOne({email: username}, function(err, foundUser){ if (err){ console.log(err); } else { if (foundUser){ bcrypt.compare(password, foundUser.password, function(err,result){ if (result === true){ res.render("secrets"); } }); } } }); }); app.listen(3000, function(){ console.log("Server started..."); });

Recibí este error después de realizar una solicitud POST en mi página de inicio de sesión, se atascó al cargar y no estaba cargando la página secrets.ejs . Creo que el error está en la ruta de inicio de login , porque recibo ese error cuando realizo una solicitud POST en la ruta de inicio de sesión.

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