Jack
Jack

Reputation: 65

Sending multiple responses(res.json) with the same response object in Express.js

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

Upvotes: 4

Views: 15140

Answers (1)

Andy Gaskell
Andy Gaskell

Reputation: 31761

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.

Upvotes: 16

Related Questions