Be the first user to complete this post
|
Add to List |
Understanding expressjs middleware with a visual example
A middleware function takes 3 arguments as seen below.
function(req, res, next){
// Your business logic goes here
}
For example, you could implement a simple request logger by defining middleware function that does just that.
function(req, res, next){
// Basic logging for all the routes
console.log(req.method + ':' + req.originalUrl);
next();
};
Also Read:
- Creating a simple event emitter using nodejs
- exports is not defined
- What does npm start do in nodejs
- Organizing your expressjs routes in separate files.
- Setup nginx with multi domain websites running on nodejs
- Resolved - Error: listen eaccess using nodejs and pm2
- What is npm shrinkwrap and when is it needed
- gzip compress and cache api response in express