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.