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

189
Views
No se pueden establecer encabezados después de que se envían al cliente - Express JS

Soy bastante nuevo en node/express y sigo un tutorial de youtube para crear una aplicación MERN Stack. Pero mi servidor de nodos está dando este error.

error

Intenté reiniciar el servidor muchas veces y sucedió una y otra vez. Tengo la idea de que sucede cuando enviamos dos respuestas para una solicitud , pero no creo que sea el caso aquí.

Por cierto, aquí está la ruta a la que apunta en el error (en la línea de respuesta de error de captura de prueba)

 // GET RANDOM router.get("/random", verify, async (req, res) => { const type = req.query.type; let movie; try { if (type === "series") { movie = await Movie.aggregate([ { $match: { isSeries: true } }, { $sample: { size: 1 } }, ]); } else { movie = await Movie.aggregate([ { $match: { isSeries: false } }, { $sample: { size: 1 } }, ]); } res.status(200).json(movie); //checked here by console logging it comes here only once } catch (err) { res.status(500).json(err); //the error pointing to this line } });

Por si acaso, aquí está el código de función de verificación:

 function verify(req,res,next) { const authHeader = req.headers.token; if(authHeader){ const token = authHeader.split(' ')[1]; jwt.verify(token,process.env.SECRET_KEY,(err,user) => { if(err) res.status(403).json("Token is not valid"); req.user = user; next(); }) } else{ return res.status(401).json("Unauthorized"); } }
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!