Im using node with express and I am calling within my node server a http get request - now when the complete data arrived from the http-request I want to call res.send
with the received data.
My code looks as follows:
app.get('/', function (req, res) {
const x = https.get(options, (req) => {
console.log('statusCode:', req.statusCode);
console.log('headers:', req.headers);
req.on('data', (locations) => {
buffer = new Buffer(locations);
console.log(buffer);
res.send(buffer); <== should sent complete result
});
}).on('error', (err) => console.log('error:', err));
x.end();
});
app.listen(port, function () {
console.log('Example app listening on port 3000!');
});
The Problem With my Code: I get everytime a different size of data - basically - everytime a incomplete set of data.