O'Reilly logo

Mastering Web Application Development with Express by Alexandru Vlăduțu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The functionality of middleware

The middleware function takes the following arguments:

  • The request object: This is a wrapper on top of the request parameter found in Node's http.createServer function, with added functionalities
  • The response object: This is another wrapper that extends the response parameter found in Node's http.createServer function
  • A callback: This is usually named next, which might get executed when everything in the current middleware is done so that the following middleware in the stack can be invoked

The following is an example of a middleware that only allows the web application to be accessed by users that are inside the private network, based on their IP address. If a user has access, we will call the next function; otherwise, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required