Skip to content

Latest commit

 

History

History
58 lines (36 loc) · 1.97 KB

README.md

File metadata and controls

58 lines (36 loc) · 1.97 KB

🔩🔩🔩What is Middleware?🔩🔩🔩

And what are Express Middlewares?

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'

3. There are two general types of Middleware - General and Service
4. Middleware allows you to integrate legacy systems

WITHIN THE CONTEXT OF EXPRESS...

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.

WHAT CAN IT DO? 🔑

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

FUNCTIONALITY 📢

screen shot 2017-12-18 at 15 26 29

USE means “Run this on ALL requests”

app.use( "/product" , mymiddleware);

  • will match /product
  • will match /product/cool
  • will match /product/foo

GET means “Run this on a GET request, for the given URL”

EXAMPLES 🔧

untitled diagram