Express.Js Middleware, What is next()?
You may have noticed use of next() function while looking at node.js code. Express is a routing web framework which utilize essentially a series of middleware calls. piece of code for a simple route could be like bellow.
1 2 3 | app.get('/users/:id', function(req, res) { // logic to fetch user for provided id. }); |
and with a additional parameter next
1 2 3 4 5 6 7 8 | app.get('/users/:id', function(req, res) { var user_id = req.params.id; if(user_id) { // do something } else { next(); // here comes middleware. } }); |
So what is next() doing here. In the example, for instance, you […]