I've found hundreds of examples of using node.js with the http or https to make a GET, POST request. Seems easy enough.
I've created a module that returns an object. In that object, I have a function called
My functon in the restlet module:
restlet.makecall = function call() {
console.log("This gets logged");
http.get('http://www.google.com/', function(res) {
console.log("statusCode: ", res.statusCode); //nothing
console.log("headers: ", res.headers); //nothing
res.on('data', function(d) {
process.stdout.write(d);
console.log("This doesn't get logged out"); //nothing
});
}).on('error', function(e) {
console.error(e);
console.log("This doesn't get logged out");
});
console.log("This gets logged");
};
My problem is that every time I run it, or any variation of code I've found in all the postings, NOTHING is logged out to the console...
I'm sure the problem is simple but I haven't figured it out. I'd really appreciate it if someone could point me in the right direction or even to a bit of code I could paste into that function that actually logged something out. (an error, anything!)
I think it's problem with your network, your callback from http.get is not being called. I would try and ping www.google.com - I suspect it won't work. Check your DNS?
I copied the code into a single .js file, and ran it, like below.
I run the code with no problems, this is the output below.