Middleware
Margaret W.N
Posted on July 22, 2020
Middleware is like a middle man in a business transaction, the only difference is middleware saves us time and money unlike middle men. It's a term coined to refer code that executes in between sending a request to a server and receiving a response. It is one way to adhere to the DRY(Don't Repeat Yourself) software development principle.
In express we use app.use ( ) to leverage on middleware function calls. We pass an arrow function to .use ( ) that takes three parameters req, res and next where next is a callback function. The callback function fires the next operation and passes the data from the arrow function.
app.use((req, res, next) => {});
So now any redundant code can be bundled up in the arrow function body, and executed in between processing the request.
Posted on July 22, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.