Firebase - npm module causes crash due to ENOTFOUND?

31 views Asked by At

Ok, figuring out npm with Firebase cloud functions here and not sure where to turn with this -

I need to use 2 NPM modules - 1 to get client's ip, the other to spit out location info based on ip. These are the modules:

https://www.npmjs.com/package/iplocation https://www.npmjs.com/package/external-ip

Firebase takes a while to deploy each time testing functions, so I started out to make sure both were working just with a simple node app on my desktop/terminal. Running node [name of js file]in terminal, everything works well with this:

'use strict';

var myIp;
const getIP = require('external-ip')();
var iplocation = require('iplocation');

myIp = getIP((err, ip) => {
    if (err) {
        // every service in the list has failed
        throw err;
    }
    console.log(ip);

    iplocation(ip)
      .then(res => {
        console.log(res);
        /* res:

          {
            as: 'AS11286 KeyBank National Association',
            city: 'Cleveland',
            country: 'United States',
            countryCode: 'US',
            isp: 'KeyBank National Association',
            lat: 41.4875,
            lon: -81.6724,
            org: 'KeyBank National Association',
            query: '156.77.54.32',
            region: 'OH',
            regionName: 'Ohio',
            status: 'success',
            timezone: 'America/New_York',
            zip: '44115'
          }

        */

      })
      .catch(err => {
        console.error(err)
      })
});

However when I go over to my firebase app, put this is in and go to my Firebase logs, I get this crashL

          Error: Multiple errors:   getaddrinfo ENOTFOUND icanhazip.com icanhazip.com:80 from http://icanhazip.com/  

getaddrinfo ENOTFOUND ident.me ident.me:80 from http://ident.me/
getaddrinfo ENOTFOUND tnx.nl tnx.nl:80 from http://tnx.nl/ip
getaddrinfo ENOTFOUND myip.dnsomatic.com myip.dnsomatic.com:80 from http://myip.dnsomatic.com/ getaddrinfo ENOTFOUND ipecho.net ipecho.net:80 from http://ipecho.net/plain getaddrinfo ENOTFOUND diagnostic.opendns.com diagnostic.opendns.com:80 from http://diagnostic.opendns.com/myip

at Object.concatErrors (/user_code/node_modules/external-ip/lib/utils.js:129:12)
at requests.(anonymous function) (/user_code/node_modules/external-ip/lib/extIP.js:34:45)
at get.concat (/user_code/node_modules/external-ip/lib/utils.js:103:24)
at ClientRequest.<anonymous> (/user_code/node_modules/external-ip/node_modules/simple-get/index.js:73:21)

With:

function returnLocation() {
  myIp = getIP((err, ip) => {
    if (err) {
        // every service in the list has failed
        throw err;
    }
    console.log("THE IP: ", ip);

    iplocation(ip)
      .then(res => {
        console.log(res);
        /* res:

          {
            as: 'AS11286 KeyBank National Association',
            city: 'Cleveland',
            country: 'United States',
            countryCode: 'US',
            isp: 'KeyBank National Association',
            lat: 41.4875,
            lon: -81.6724,
            org: 'KeyBank National Association',
            query: '156.77.54.32',
            region: 'OH',
            regionName: 'Ohio',
            status: 'success',
            timezone: 'America/New_York',
            zip: '44115'
          }

        */

      })
      .catch(err => {
        console.error(err)
      })
});


}
exports.enterLocation = functions.database.ref('/Users/{name}') //brackets is client param
    .onWrite(event => {
      //console.log('SKYLAR HERE:', event.params.name);
      returnLocation();
      //-----------------------------------------

      return event.data.adminRef.set({ location: 'test loc'});
  });

Clearly 1 of my modules or both makes a call to http, which I understand firebase doesn't like/support.

What is the solution here? Am I supposed to make sure ANY dependencies I use don't use http but https? Is this even the problem?

0

There are 0 answers