In this video we are going to learn about Middleware.
Middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application's request-response cycle.
The next middleware function is commonly denoted by a variable named next.
In express we can use application level middleware and route level middleware.
So lets see application level middleware first.
So goto the index.js file and here add middleware with the app.


App.use(function(req,res,next){
console.log('Time: ' , Date.now())
});



Now save and lets run this.
So switch to the command prompt and run index.js file.


node index.js


Now got the browser and go to url localhost:3000.
You can see here application level middleware is apllied, the current date and time is showing here Now if change the route.
If i go to the url /about.
You can see the data time and if I change with the url /contact.
Its still showing the date and time.
So, middlare is applied on whole application.
Now lets see the route level middleware.
For that go to the index.js file and lets add the middleware to the about route.


app.get('/about', function (req, res, next) {
console.log('Time: ' , Date.now())
res.render('about');
});



Now lets run this.
So go to the command prompt and re-run the index.js file.


node index.js


Now lets check.
So switch to the browser and go to the url /about.
You can see here the date time and if change the url like contact.
Its not showing So in this way you can use middleware.