O'Reilly logo

Pro Express.js by Azat Mardan

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

CHAPTER 4

image

Working with Middleware

Middleware is an amazingly useful pattern that allows developers to reuse code within their applications and even share it with others in the form of NPM modules. The essential definition of middleware is a function with three arguments: request (or req), response (res), and next. If you’re writing your own middleware, you can use arbitrary names for arguments, but it’s better to stick to the common naming convention. Here’s an example of how to define your own middleware:

var myMiddleware = function (req, res, next) {  // Do something with req and/or res  next();};

When writing your own middleware, don’t forget ...

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