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:
- Debugging nodejs applications using node-inspector and Chrome Dev Tools
- What is an npmignore file and what is it used for
- Resolved - sudo npm command not found
- Testing promise sequence using mocha, chai, chai-as-promised, sinon
- Installing, Listing and Uninstalling packages using npm
- set the default node version using nvm
- Accessing the request body and session in nodejs using express
- Setup passportjs for local authentication and authorization using expressjs