firebase-functions: ERROR: getaddrinfo ENOTFOUND

Version info

firebase-functions: 0.5.7

firebase-tools: 3.9.1

firebase-admin: 4.2.1

Test case

Hello. Thank you for read me.

I have the following case: I’m trying to do an http GET request from firebase function, this is my code: (I’m using a test API from “jsonplaceholder” just to get Random Data and then test my real functionality.)

const functions = require('firebase-functions');
const http = require('http');

exports.myFunction= functions.https.onRequest((request, response) => {
     var options = {
          host: 'jsonplaceholder.typicode.com',
          path: '/posts/1',
     };

    var req = http.get(options, function(res) {
    console.log('STATUS: ' + res.statusCode);
    console.log('HEADERS: ' + JSON.stringify(res.headers));

    // Buffer the body entirely for processing as a whole.
    var bodyChunks = [];
    res.on('data', function(chunk) {
        bodyChunks.push(chunk);
    }).on('end', function() {
        var body = Buffer.concat(bodyChunks);
        console.log('BODY: ' + body);
        })
    });

    req.on('error', function(e) {
    console.log('ERROR: ' + e.message);
    });

    response.send("Hello from Firebase!"); //just to send something in response.
 }

Steps to reproduce

When I test that function in my LOCAL environment on a test case using node index.js, everything works just fine!

Were you able to successfully deploy your functions?

When I do firebase deploy everything deploys just fine, the function is uploaded to my function dashboard.

Expected behavior

The expected behavior is that the log printing the body returns something like:

STATUS: 200
BODY: {
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae 
    ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

Actual behavior

The actual behavior is this:

ERROR: getaddrinfo ENOTFOUND https://jsonplaceholder.typicode.com https://jsonplaceholder.typicode.com:443

Thats what’s happening when I trigger the function on firebase, but in my local environment everything work ust fine… is that a bug?

Thank you very much!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 23 (2 by maintainers)

Most upvoted comments

i solved it by following this few steps. run firebase deploy again after the error

seeing the same error, on a payed (blaze) account

use firebase init hosting but don’t overwrite then deploy

btw, problem is because on free version of firebase you can’t make external network calls. call to instamojo from firebase is external. Switch to braze or paid version of firebase.

Hi, you are probably seeing this error because you need to be on a paid plan in order to make external HTTP requests from inside your function. If you look at your Functions logs from within the Firebase console, you should see error messages indicating this.

Firebase’s Blaze plan (pay as you go) has a free tier for Cloud Functions, details here: https://firebase.google.com/pricing/

use firebase deploy before your actual command. it worked for me 😃