Имеется функция, выполняющая запрос к API. Не понимаю, как вернуть значение из асинхронной функции request
request(urlPart: string) {
const auth =
"Basic " +
Buffer.from(this.username + ":" + this.httppass).toString("base64");
const http = require("http");
http
.get(
this.url?.concat(urlPart),
{ auth: this.username + ":" + this.httppass },
(resp: any) => {
let data = "";
// A chunk of data has been recieved.
resp.on("data", (chunk: any) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on("end", () => {
return JSON.parse(data.substr(5).substring(0, data.length - 1));
});
}
)
.on("error", (err: any) => {
return JSON.parse(err.message);
});
}