1. Middleware provides services to software application beyond those provided by ones own Operating System.
2. It is the software layer that lies between the OS and the applications on each side of a network. 'Software Glue'
Middleware can refer to any number of functions that are invoked by the Express.js routing layer before the final request handler is made.
Middleware functions are functions that have access to the request object (req), the response object (res), and the NEXT middleware function in the application’s req-res cycle. All middleware functions can include the ‘next’ perimeter so that it can pass things along until the final function when it is no longer needed.
Middleware functions can perform tasks such as:
- Executing any code
- Making changes to the req-res object
- Ending the req-res cycle
- Calling the next middleware function in the stack.
Express Applications can use the following levels of middleware:
- Application-level middleware
- Router-level middleware
- Error-handling middleware
- Built-in middleware
- Third-party middleware
app.use( "/product" , mymiddleware);
- will match /product
- will match /product/cool
- will match /product/foo