Lesson 6. Writing better routes and serving external files

In lesson 5, you directed URL traffic with a routing system that matched request URLs to custom responses. In this lesson, you learn how to serve whole HTML files and assets such as client-side JavaScript, CSS, and images. Say goodbye to plain-text responses. At the end of the lesson, you improve your route code and place your logic in its own module for cleaner organization.

This lesson covers

  • Serving entire HTML files by using the fs module
  • Serving static assets
  • Creating a router module
Consider this

It’s time to build a basic recipe website. The site should have three static pages with some images and styling. You quickly realize that all the applications you’ve built ...

Get Get Programming with Node.js now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.