G
G
Grigory Vasilkov2017-01-06 11:55:57
Express.js
Grigory Vasilkov, 2017-01-06 11:55:57

When is next() used in Express?

According to the documentation - in order to proceed to the processing of the next controller mmm chtoli ...
That is, there it is like this:

req.get("/", function (req, res, next) {
  // ... code
 next();
}, function (req, res) {
 // ... code
});

The meaning of how it works is clear, another question is under what circumstances do you really need to move on to the next action? What prevents this action from being called inside the first one, why is there support for several in a row? Or does it make sense to delay the call?
Does anyone use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2017-01-06
@gzhegow

Here we are not talking about "controllers", but about middleware . And in this context, the call chain becomes clear. For example:
The main reason for this architecture is an attempt to get rid of callback-hell. In Express, everything is on callbacks, which are poorly adapted to asynchrony, in fact. So they came up with such "promises for the poor" (here I greatly simplified, of course).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question