Node.js External HTTP Call

Write a node.js program for making external http calls.

Solution

It is often necessary for a network application to make external HTTP calls. HTTP servers are also often called upon to perform HTTP services for clients making requests. Node provides an easy interface for making external HTTP calls. For example, the following code will fetch the front page of google.com.

var http = require('http');
http.request({
host: 'www.google.com',
method: 'GET',
path: "/"
}, function(response) {
response.setEncoding("utf8");
response.on("readable", function() {
console.log(response.read())
});
}).end();

Read more articles


General Knowledge



Learn Popular Language