Cover by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required