How do I return data from inside an https.request
?
Here is my https request function, which works fine:
var req = https.request(options, (res) => {
console.log('statusCode: ', res.statusCode);
res.on('data', (d) => {
var l = JSON.parse(d);
console.log(l.firstName);
//The Retuned JSON is HERE <—————————————- HERE
});
});
req.end();
req.on('error', (e) => {
console.error(e);
});
//What I need is the retuned JSON file here <——————————I NEED IT HERE
I would normally just return some value inside each nested function but with the https.request
I am unsure how this works.