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

1
  • plz mention your code so that we can help as per your requirement Commented Aug 2, 2017 at 13:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

FWIW, I used Andy's explanation to do res.json({responseObjects: myArrayOfJSONObjects}) in an Express.JS and Node.JS configuration. Worked perfectly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.