You are previewing Node Web Development.

Node Web Development

Cover of Node Web Development by David Herron Published by Packt Publishing
O'Reilly logo

Implementing a basic web server

This section presents the implementation of Basic Server, a basic web server. While Node includes an excellent HTTP Server object there are several additional protocol elements and services to wrap around that object to provide common website features.

Basic Server is, well, pretty basic. It demonstrates a way to implement some features including the following:

  • Flexible request routing
  • Automatically provide a parsed URL object
  • Automatically extract the Host header (for virtual hosting)
  • Automatically extract Cookie headers
  • Satisfy favicon.ico requests
  • Serving static files (HTML, JS, PNG, GIF, JPEG, and so on).
  • Flexible server configuration

With these as the goals the following code comprises four Node modules, a CSS file, ...

The best content for your career. Discover unlimited learning on demand for around $1/day.