I try to read and parse Data from an external API with NodeJS, but I am not able to write the parsed Object into something outside of the get() methode.
function Profile(username) {
const https = require("https");
const request = https.get(
`https://teamtreehouse.com/${username}.json`,
res => {
let body = "";
const request = res.on("data", d => {
body += d.toString();
});
res.on("end", () => {
var profile = JSON.parse(body);
this.objPropOne = profile;
});
}
);
this.objPropTwo = request;
}
const objResult = new Profile("chalkers");
console.log(objResult);