I am doing an HTTPS request that stores the data received in a variable. When the request ends all the data will be parsed to JSON and the code will proceed. But I can't type the code outside of the end listener since it proceeds with the code without the request ending. I don't want to type my code in the end listener. What do I do?
const https = require("https");
let templateData = "";
https.get("https://templates.xenon.bot/api/templates/nuAcXSXQc9cM", async (res) => {
res.on("data", (ch) => {
// data listener
templateData += ch;
}).on("end", () => {
// end listener
templateData = JSON.parse(templateData);
});
}).end();
// rest of code (logs undefined since it doesn't execute after end)
console.log(templateData.creator);