Skip to content

How can we implement a fully streaming-compatible middleware pipeline in Express without buffering the request/response? #6686

Discussion options

You must be logged in to vote

Great question! In Node.js, request streams (req) are “consumable” once you pipe or read from them in a middleware, the data is gone and later middleware can’t re-read that stream. Basically, the stream doesn’t “reset” after it is been read.

So if you need multiple transformations, you will want to chain them together in the same middleware (using something like stream.pipeline() or by piping through multiple Transform streams in one go), rather than trying to process req in separate, later middleware.

If you must split logic across middleware, you would have to buffer the body yourself (which kinda defeats the purpose for large uploads).

That is why for streaming use cases, it is best to…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zeeshanmazhar
Comment options

@Yasir-Rafique
Comment options

Answer selected by zeeshanmazhar
@zeeshanmazhar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants