Search code examples
javascriptnode.jsexpressmiddleware

In express js, does too many middleware functions decrease performance?


I'm developing (my coworkers and I) an application with express js and I've been looking for information for any performance issue when you add too many middleware functions in the server configuration, but I haven't found anything related.

In my case, for instance, I have added the typical middleware: the handler for static resources, a cookie parser, a body parser, a compressor... and we are thinking to add many more, even custom functions developed by us.

So my question is, is there any moment, any number of handlers, which could cause a performance issue in the application? Or is there anywhere a summary related to this or any tests done by someone?

Thanks.


Solution

  • Every piece of middleware is a piece of code that gets run for every request.

    Each one will degrade performance. Maybe a little, maybe a lot, it depends on what the code does.