K
K
komigor2021-02-17 20:32:07
Express.js
komigor, 2021-02-17 20:32:07

Is an intermediate event handler also middleware or not?

It is clear what midlware is, this is the code that is executed between the request and the response, it has access to the request and response object, etc. but in the code I once met a code like this

app.get('/',  (req, res, next) =>) 
// to do
next(err)

Is it an intermediate event handler?
But the question is how does it differ from middleware which is in app.use(...)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2021-02-18
@komigor

Nothing, it's all middleware. The essence of the intermediate handler is that it must be called at the very end and either terminate the process or pass req / res objects to the next intermediate state.
Here you can see the implementation inside express, and here you can read how the whole thing works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question