Express - Types of Middleware's Flashcards

1
Q

What types of middleware are there in Express.js?

A
  1. Application-level middleware
  2. Router-level middleware
  3. Error-handling middleware
  4. Built-in middleware
  5. Third-party middleware
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between application-level & route-level middleware?

A

Application-level applies globally to all incoming requests and middleware applies only to specific routes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is error handling middleware and how to implement it?

A

app.use(err, req, res,next)

Using the err parameter we can check for errors and handle them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you have 5 middlewares, in which middleware will you do the error handling?

A

In the last middleware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is built in middleware? How to serve static files from Express.js?

A

Built in middleware are functions provided by Express.js

app.use(express.static(‘/public’))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are third-party middlewares?

A

Middlewares we can install using npm install.

Examples helmet, body-parser, compression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly