Hello I have this Problem
I dont now how can code it
The Console.log output is: undefined
it would be helpful if someone could help me!
function GetJsonApi(url) {
let result;
if (url.startsWith('http://')) {
http.get(url, (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
var result = json;
} catch (error) {
var result = error.message;
};
});
}).on("error", (error) => {
var result = error.message;
});
return result;
}
}
console.log(GetJsonApi('https://ipinfo.io/1.1.1.1/json'))