What is Middleware?

What is Middleware?

middleware in details

  • In a very simple language middleware are like a guard or we can say that they are like a ticket checker in a train.

  • That are placed just before any website's route handler or we can say end points of a website.

  • For example - In a website what kind of routs or end points can be there which are common

    1.) Sign up

    2.) Password

  • These two end points are very common which are present in almost every website.

  • Before any user enters their details to these routs or end points.

  • They are passed to the middleware where they check that the information entered are as expected or not.

  • If not then the user is not allowed to enter and vice-versa.

  • Middleware functions have the access to three inputs they are as follows

    1.) req [request object]

    2.) res [response object]

    3.) next [which calls the next function]

  • Here is an example

  • Output

  • This an example that how a middleware works.