This is a deliberate aspect of the Connect design (the node.js middleware responsible for this behavior). The next function that your middleware receives is not the next middleware on the stack; this is a function that Connect creates that requests the next middleware to process it (and also does some extra stuff to handle special cases, like when there is no โnext middlewareโ).
If your middleware should return a response, just do it. If this is not the case, this implies that some later middleware should return a response. If you need to pass data to this later part of the process, you must attach it to the corresponding part of the req request object.
For example, the associated bodyParser middleware is responsible for populating req.rawBody and req.body based on the contents of the request body. The basicAuth related middleware populates req.remoteUser based on HTTP authentication.
This is the pattern you should try to emulate: a middleware stack, each of which performs a basic incremental operation to process the request. If what you are trying to simulate does not fit into this paradigm, then you probably should just have one function to handle the request, from which you can call all your own application logic as you like.
source share