I'm having an issue sending the same json object to two separate endpoints. I need to send one copy to a database, and the other copy back to the client. I'm getting can't set headers after they are sent
. Which I have gathered is an error saying that res.json()
is called once, and can not be called a second time because the headers have been "baked in". I'm pretty newb to development, any suggestions or explanation would be very helpful.
Note: the whole code executes successfully, then crashes the server with the error message above.
paypal.payment.execute(paymentId, execute_payment_json, function (error, payment) {
if (error) {
console.log(error.response);
throw error;
} else {
console.log("Get Payment Response");
console.log(JSON.stringify(payment));
const userData = {paymentID : payment.id};
UserData.addUserData(userData, function(err, userData) {
if (err) {
throw err;
}
res.json(userData);
});
res.json(userData)
}
});
})