I'm trying to use request to make a request to this api https://api.ipify.org/?format=json and receive back some json like this {"ip":"XX.XX.XXX.XX"} from there I want to parse it and let my function's callback console.log the ip.
I'm just learning about callbacks and async so please give me any advice you can :)
const url = 'https://api.ipify.org/?format=json';
const getMyIP = function (callback) {
request(url, (error, body, _response) => {
body = JSON.parse(body);
const ip = body["ip"];
return ip;
});
};
getMyIP((error, ip) => {
if (!error) {
console.log(ip);
}
});
ip, just call your callback.