Now that we've looked deeply at the HTTP server object, let's jump over to the other end of the wire. Node includes an HTTP Client object useful for making HTTP requests. It's enough to issue any kind of HTTP request, but for example it does not emulate a full browser so don't get delusions of this being a full scale test automation tool. With it you can build browser emulators or any other sort of HTTP client. For example, any REST web service can be called through an HTTP client object.
Let's start with some code inspired by the
curl commands to make HTTP requests and show the results. Create a file named
wget.js containing this code:
var http = require('http'); var url = require('url'); var util = require('util'); ...