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

81
Views
Node.JS envía resultados después del bucle for

Tengo un problema con mi controlador en Node.Js. Primero encuentro todos los productos relacionados con un atuendo y luego recorro todos los productos para obtener la información relacionada con eso. Las consultas funcionan, pero aparece el error "No se pueden establecer encabezados después de enviarlos al cliente" o el cuerpo es una matriz vacía. Este es mi código.

 const Outfits = require("../models/Outfits"); const Products = require("../models/Products"); module.exports = async (req, res) => { Outfits.find({ outfitId: req.params.id }, (error1, result) => { if (error1) { res.status(400).json({ status: "fail", }); } else { let productIds = result[0].productIds; let productsList = []; productIds.forEach((id) => { Products.find({ id: id }, (error2, products) => { if (error2) { res.status(400).json({ status: "fail", }); } else { productsList.push(products); console.log(productsList); } }); }); res.status(200).json({ status: "success", body: productsList, }); } }); };

¿Tienes alguna sugerencia? ¡Gracias!

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!