0

Error

Error: { [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
hostName: 'api.v3.factual.com'                 
url : http://api.v3.factual.com/t/places?geo=%22$point%22:12.9361149,77.6159516]}&q=Cool%20Roll%20Burger&KEY=ApiKey 

Code

function internalHttpApiCall(hostName,url,callback)
{

    var options = {
    hostname : hostName,    
    port: 4456,
    path: url,
    method: 'GET',
    }

/* A similar https call works just fine. I have taken the following links as reference for solving the problem. How can I use an http proxy with node.js http.Client? How can I use an http proxy with node.js http.Client? */

    var response="";

    var req = http.request(options, function(res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);
    console.log(options.path);

    res.on('data', function(d)  { 
        response += d; 
    });

    res.on('end', function() {
        if (response && JSON.parse(response))
        {   
            var obj = JSON.parse(response)
            console.log(obj);
            output();
        }
    });

    });

    req.end();

    req.on('error', function(e) {
        console.error(e);
    });

    function output(xresponse)
    {
        callback(xresponse);
    }
}
Community
  • 1
  • 1
Anurag Narra
  • 95
  • 1
  • 9

1 Answers1

0

Just remove the port atribute from the options object. When you pass a port to the options object, you're saying that you want to make a request to that specific port, like http://api.v3.factual.com:4456. Since they expose just their URL, we don't know which port they are using behind the scenes. Thus, it's not necessary.

And also remove the missed , after the method: 'GET' option.

var options = {
  hostname: hostName,
  path: url,
  method: 'GET'
}
Rodrigo Medeiros
  • 7,814
  • 4
  • 43
  • 54