4
res.json(Object.assign({}, cart.generateArray()));
res.json(JSON.stringify(cart.totalPrice));

how can i send Sending multiple responses because my code doesn't work

thank you

Jack
  • 65
  • 1
  • 1
  • 5

1 Answers1

16

You cannot send multiple responses. You send an object that contains your array and total price:

res.json({
    items: cart.generateArray(),
    totalPrice: cart.totalPrice
});

Another option would be to make two different requests if you need two responses.

Andy Gaskell
  • 31,495
  • 6
  • 74
  • 83
  • FWIW, I used Andy's explanation to do res.json({responseObjects: myArrayOfJSONObjects}) in an Express.JS and Node.JS configuration. Worked perfectly! – Chris C Jan 17 '19 at 18:10