I tried to make an https call and return the body containing the data, but when I tried to print it in the console it returned undefined so I used the "promises".
const https = require('https');
const baseUri = "https://apiv2.gofile.io/"
class apiGofile {
constructor(email,apikey) {
this.email=email;
this.apikey=apikey;
}
getBestServer() {
return new Promise((resolve,reject)=>{
https.get(baseUri + "getServer", (res) => {
let body="";
res.on("data", (data) => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
resolve(body.data.server);
});
res.on("error",(e)=>{
reject(e);
});
});
});
};
}
let a = new apiGofile("a","b");
a.getBestServer()
.then(
response => console.log(response),
error => console.log(error)
);
is there any way to use await and async in my code?