December 2014
Intermediate to advanced
160 pages
3h 4m
English
CHAPTER 2
![]()
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 ...
Read now
Unlock full access