Don’t use bodyParser middleware anymore with ExpressJS…

When you work with an express server, you can use the bodyParser middleware to your app with the app.use() function to extract the body of request stream to attach it to the req.body object.

You can then process the req.body object to manipulate data for your business logic.

Sometimes, when you work with a lots of data, you could see an error from your express server: “Request entity too large”, which means that you reach the default limit (100kb) managed by the body parser middleware.

In my case it was a page builder that sent html, css, and components of a library to my Express server, making the weight of the body request too heavy and this error appears, preventing our client to create more content.

With the bodyParser middleware, you can pass it some options to increase the size of your body request and let all your data pass to your back-end like this:

After some research in stack overflow and more, I saw a lot of people get confused about the way to manage this limit, the main recurrent question is: Should I use body parser or express built-in middleware, or maybe both…?

Since we have Express 4.16, there is a built-in middleware function in Express based on bodyParser so you don’t need it anymore, you can use the middleware and pass options like this:

Be sure to don’t use them all together, and, of course it works with urlencoded, raw and others…




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store