<author>/<type>/<ticket>/<title>
revett/feature/24101/skeleton-service-for-email-sender
So far we've handled our requests and responses with ease. But we still haven't seen how Express solves the annoying problem of routing the many resources and pages that a modern website may have.
Let's imagine that our website has a sub-page dedicated to a collection of kittens at '/kittens'.
Easy, right? As we saw before, we could just add a route to our app like this:
app.get('/kittens', function(request, response, next) {
Middleware refers to modules that are chained 'between' when your Express app is instantiated and when your server is launched with app.listen(myPortNumber)
.
We'll stick to two easy examples that illustrate the usefulness of middleware: logging and static resources.
Using middleware is simple. Use Node.js to require
the package that you'd like to use. Then add the middleware to your app by calling it with .use()
. The order that you call your middleware may matter, so look in the docs for your middleware to make sure it's well-positioned.
Here's how we would deploy the logging middleware Morgan.