I use Express.js ver 4.2 and want to parse a large post (150K - 1M) but receives the error message "request entity too large". It seems that the limit is 100 K. I don't now how to change the limit in Express 4. In Express 3.x I just did -
app.use(express.json({limit: '5mb'})); app.use(express.urlencoded({limit: '5mb'}));
How can I change the limit in Express 4 ?
Thanks for any help.
The good news is that as of Express version 4.16+, their own body-parser implementation is now included in the default Express package so there is no need for you to download another dependency.
This how to use body-parser in express: const express = require('express'), app = express(), bodyParser = require('body-parser'); // support parsing of application/json type post data app. use(bodyParser. json()); //support parsing of application/x-www-form-urlencoded post data app.
body parser package is deprecated. If you are using latest version of express you don't have to install body-parser package.
Body-parser is the Node. js body parsing middleware. It is responsible for parsing the incoming request bodies in a middleware before you handle it.
With Express 4 you have to install the body-parser
module and use that instead:
var bodyParser = require('body-parser'); // ... app.use(bodyParser.json({limit: '5mb'})); app.use(bodyParser.urlencoded({limit: '5mb'}));
Mscdex's code works, but we should add another parameter to avoid warning now.
app.use(bodyParser.urlencoded({limit: '5mb', extended: true}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With