Middleware Basics5:05 with Joel Kraft
Practice the basic mechanics of Express middleware.
You might notice the
fav.js file used in this basic app. You can ignore it for now, but in case you're curious why it's there, read on! When you navigate to a URL with a browser, it will usually make two requests behind the scenes. One request will be for the resource you're requesting, usually a webpage, and the other will be for a favicon file to display in the browser's tab.
This means that if a middleware function logs a message to the console with every request (as some of the ones we will write do), that message will appear twice with every page refresh!
fav.js is a small piece of middleware that circumvents this issue so that we can read the output in this workshop without distraction. By the way, after you complete this workshop, you should be able to understand the code in
fav.js only exists for educational purposes, and should not be included in a production app. A real-life application should always supply a favicon to the browser.
You need to sign up for Treehouse in order to download course files.Sign up