July 2012
Beginner to intermediate
342 pages
7h 27m
English
The HTTP object doesn't just provide server capabilities, it also affords us with client functionality. In this task, we're going to use http.get with process to fetch external web pages dynamically via the command line.
We are not creating a server, so in the naming convention we should use a different name for our new file, let's call it fetch.js.
http.request allows us to make requests of any kind (for example, GET, POST, DELETE, OPTION, and so on), but for GET requests we can use the short-hand http.get method as follows:
var http = require('http'); var urlOpts = {host: 'www.nodejs.org', path: '/', port: '80'}; http.get(urlOpts, function (response) { response.on('data', function (chunk) ...Read now
Unlock full access