When using Node.js to try and get the html content of the following web page:
eternagame.wikia.com/wiki/EteRNA_Dictionary
I get the following error:
events.js:72 throw er; // Unhandled 'error' event ^ Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16)
I did already look up this error on stackoverflow, and realized that this is because node.js cannot find the server from DNS (I think). However, I am not sure why this would be, as my code works perfectly on www.google.com
.
Here is my code (practically copied and pasted from a very similar question, except with the host changed):
var http = require("http"); var options = { host: 'eternagame.wikia.com/wiki/EteRNA_Dictionary' }; http.get(options, function (http_res) { // initialize the container for our data var data = ""; // this event fires many times, each time collecting another piece of the response http_res.on("data", function (chunk) { // append this chunk to our growing `data` var data += chunk; }); // this event fires *one* time, after all the `data` events/chunks have been gathered http_res.on("end", function () { // you can use res.send instead of console.log to output via express console.log(data); }); });
Here is the source where I copied and pasted from : How to make web service calls in Expressjs?
I am not using any modules with node.js.
Thanks for reading.
The error getaddrinfo ENOTFOUND localhost is caused by Webpack cannot found localhost address. To solve it, open the terminal: sudo nano /etc/hosts. Add following into the hosts file and save it.
getaddrinfo ENOTFOUND means client was not able to connect to given address.
In Node.js HTTP
module's documentation: http://nodejs.org/api/http.html#http_http_request_options_callback
You can either call http.get('http://eternagame.wikia.com/wiki/EteRNA_Dictionary', callback)
, the URL is then parsed with url.parse()
; or call http.get(options, callback)
, where options
is
{ host: 'eternagame.wikia.com', port: 8080, path: '/wiki/EteRNA_Dictionary' }
Update
As stated in the comment by @EnchanterIO, the port
field is also a separate option; and the protocol http://
shouldn't be included in the host
field. Other answers also recommends the use of https
module if SSL is required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With