I'm a begginer in node.js and now I'm trying to get API's result from http.get. But, when running the code I'm receiving this error:
Error: getaddrinfo ENOTFOUND
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
I'm requiring http correctly (I had it tested to be sure) Here is my function to illustrate the problem:
function getData(apiUrl, getUrl) {
var options = {
host : apiUrl,
port : 80,
path : getUrl
};
var content = "";
http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
res.on("data", function(chunk) {
content += chunk;
console.log(content);
});
}).on('error', function(e) {
console.log("Error: " + e.message);
console.log( e.stack );
});
}
And calling it this way:
getData('https://api.twitter.com', '/1/statuses/user_timeline.json?&screen_name=twitter&callback=?&count=1');
Hope you can help me, thanks!