Express - Types of Middleware's Flashcards
What types of middleware are there in Express.js?
- Application-level middleware
- Router-level middleware
- Error-handling middleware
- Built-in middleware
- Third-party middleware
What is the difference between application-level & route-level middleware?
Application-level applies globally to all incoming requests and middleware applies only to specific routes.
What is error handling middleware and how to implement it?
app.use(err, req, res,next)
Using the err parameter we can check for errors and handle them.
If you have 5 middlewares, in which middleware will you do the error handling?
In the last middleware.
What is built in middleware? How to serve static files from Express.js?
Built in middleware are functions provided by Express.js
app.use(express.static(‘/public’))
What are third-party middlewares?
Middlewares we can install using npm install.
Examples helmet, body-parser, compression