Added listener for 'end of stream' event. The current code failed on multiple requests because it prematurely sends the response to the callback, and JSON.parse is called on an incomplete json document. Adding the 'end' event listener keeps the connection open until the entire document is received.
Added listener for 'end of stream' event. The current code failed on multiple requests because it prematurely sends the response to the callback, and JSON.parse is called on an incomplete json document. Adding the 'end' event listener keeps the connection open until the entire document is received.