Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Express. Large body for bodyParser


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.

like image 971
user2856066 Avatar asked Aug 15 '14 19:08

user2856066


People also ask

Does Express include bodyParser?

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.

How use bodyParser Express JS?

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.

Is bodyParser deprecated 2021?

body parser package is deprecated. If you are using latest version of express you don't have to install body-parser package.

What does bodyParser do in node JS?

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.


2 Answers

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'})); 
like image 98
mscdex Avatar answered Sep 30 '22 07:09

mscdex


Mscdex's code works, but we should add another parameter to avoid warning now.

app.use(bodyParser.urlencoded({limit: '5mb', extended: true})); 
like image 25
blackmiaool Avatar answered Sep 30 '22 07:09

blackmiaool