Virtual hosting is a method of hosting multiple domain names on the same IP address. As Basic Server shows, Node is capable of implementing name-based virtual hosting.
In name-based virtual hosting, the HTTP request will include a Host header specifying the domain name:
GET /path/to/request HTTP/1.1 Host: example.com
In Node the
req object contains an array named
headers which will contain the Host header. As Basic Server demonstrates, virtual hosting is easily implemented by inspecting the
headers array and directing the request appropriately to the requested domain.