0

Good morning, please I'm trying to return array value from function... but it always result in undefined when I try to use any value of the array like GetASN('128.101.101.101').autonomousSystemNumber and promise { } when I try to return the whole array...

please note that I tried these methods too but it didn't work...: https://stackoverflow.com/a/61719247/8704593 https://stackoverflow.com/a/51882019/8704593


async function GetASN(ipaddress) {
        if(validateIPAddress(ipaddress) == false) return null;

        let GeoResponse = {};
        GeoIPReader.open(path.join(__dirname, 'databases/GeoLite2-ASN.mmdb')).then(await function (reader) {
            GeoResponse = reader.asn(ipaddress);
            console.log(GeoResponse.autonomousSystemNumber);
            console.log(GeoResponse.autonomousSystemOrganization);
        });
        return GeoResponse;
}

Zorono
  • 75
  • 2
  • 12
  • You need to return the Promise - right now you're returning the object before it's been populated. `return GeoIPReader.open` then modify the object and return it *inside the `.then`*. (also, `await function` doesn't make sense, just use `function`) – CertainPerformance Dec 20 '20 at 22:57
  • sorry... i didn't understand you, please can you explain – Zorono Dec 20 '20 at 23:13
  • thanks dude!!! it worked... (in fact, it token much time to understand what you meant) – Zorono Dec 20 '20 at 23:33

0 Answers0