I am trying to get hands on Node.js. Here is the very simple code I was playing with
var http = require('http');
http.get('www.google.com', function(res) {
console.log(res.statusCode);
});
I got the following error upon running this code
events.js:141
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:837:11)
at exports._exceptionWithHostPort (util.js:860:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)
upon reading the error output, I added two more lines of code to handle error event like below
var http = require('http');
http.get('www.google.com', function(res) {
console.log(res.statusCode);
res.on('error', function(error) {
console.error(error);
});
});
but the same error message was still persisting, where am I messing it up?