Cloud Functions for Firebase - getaddrinfo ENOTFOUND

node.jsFirebasePaypalDnsGoogle Cloud-Functions

node.js Problem Overview


Trying to make a request to Paypal's API using PayPal-node-SDK

exports.requestPayment = functions.https.onRequest((req, res) => {
    return new Promise(function (fullfilled, rejected) {
        paypal.payment.create(create_payment_json, {}, function (error, payment) {
            if (error) {
                rejected(error);
            } else {
                console.log("Create Payment Response");
                console.log(payment);
                res.status(200).send(JSON.stringify({
                    paymentID: payment.id
                })).end();
                fullfilled(payment);
            }
        });
     });
});

but I'm constantly getting an error:

Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

Things I've tried:

  1. Making a request to a totally different host, still ENOTFOUND
  2. Wrapping the request with cors(req,res, ()=>{...})
  3. Prepending https:// to the host

What is the problem?

node.js Solutions


Solution 1 - node.js

You'll need to be on a paid plan to make external API requests.

Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/

Solution 2 - node.js

in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.

Solution 3 - node.js

You need to include service account to the admin initialization. this fixed the same issue for me

Solution 4 - node.js

Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator to see what you'd be charged for a given usage.

The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

Solution 5 - node.js

I was having this issue because of weak internet, change the internet connection.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser47376View Question on Stackoverflow
Solution 1 - node.jsJames DanielsView Answer on Stackoverflow
Solution 2 - node.jsLevi WinansView Answer on Stackoverflow
Solution 3 - node.jsEngrEricView Answer on Stackoverflow
Solution 4 - node.jskynanView Answer on Stackoverflow
Solution 5 - node.jsSayyam abbasiView Answer on Stackoverflow