You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document customizing express.json() size limit for specific routes #1421
In the following issue, it is requested to customize the body size limit for express.json() dynamically based on the API route:
@marbuser (Apr 11, 2019):
I've got some endpoints and 90% of them I want to have a limit of around '2MB'. However, there is 1 specific route, my upload route, where I want to have an upload limit of '10MB'.
There are some solutions provided in the thread, but maybe a simpler option would be this one inspired by this Stack Overflow answer:
// Parse application/json// - limit on /upload: 5MB// - limit on other routes: default of 100KBapp.use('/upload',express.json({limit: '5mb'}));app.use(/^(?!\/upload$)/,express.json());
The root issue expressjs/express#3932 that inspired this issue is really about understanding middleware ordering and targeting specific routes with specific middleware, not about bodyParser.limit setting really.
I understood expressjs/express#3932 to be about "how can I configure the /upload route with a certain limit and non-/upload routes with a different limit?" since that is the case provided in that issue description at the top of the page.
I think my issue #1421 doesn't subvert that original wish.
Activity
itsalb3rt commentedon Dec 31, 2023
For future people here, I have a problem because I forgot my pre-fix API structure, all my endpoints start with
APIfor example
api/upload/add example for route-specific limits (expressjs#1421)
docs(express.json): add example for route-specific limits (expressjs#…
jonchurch commentedon Sep 22, 2025
The root issue expressjs/express#3932 that inspired this issue is really about understanding middleware ordering and targeting specific routes with specific middleware, not about bodyParser.limit setting really.
karlhorky commentedon Sep 23, 2025
@jonchurch hmm not sure what you mean.
I understood expressjs/express#3932 to be about "how can I configure the
/uploadroute with a certain limit and non-/uploadroutes with a different limit?" since that is the case provided in that issue description at the top of the page.I think my issue #1421 doesn't subvert that original wish.
Do you disagree with either of those things?
docs(express.json): add route-specific limit example (fixes expressjs…