How to fix PayloadTooLargeError: request entity too large (body-parser limit exceeded) in Node.js

Node.jsINTERMEDIATEMEDIUMUpdated Dec 9, 2025· 178 views

This error occurs when a POST or PUT request sends more data than Express's body-parser middleware allows. By default, Express limits JSON payloads to 100KB. Increase the limit in your middleware configuration to fix this.

Quick fix

Fixes PayloadTooLargeError: request entity too large (body-parser limit exceeded)

const express = require('express');
const app = express();

// Increase JSON payload limit to 50MB
app.use(express.json({ limit: '50mb' }));

app.post('/api/data', (req, res) => {
  // Now accepts payloads up to 50MB
  res.json({ received: req.body });
});

app.listen(3000);
  1. Identify which body-parser middleware is rejecting the request
  2. Increase the limit in express.json() for JSON payloads
  3. Increase the limit in express.urlencoded() for form data if applicable
  4. For file uploads, configure multer with a fileSize limit
node.js — error
const express = require('express');
const app = express();
// Increase JSON payload limit to 50MB
app.use(express.json({ limit: '50mb' }));
app.post('/api/data', (req, res) => {
// Now accepts payloads up to 50MB
res.json({ received: req.body });
});
app.listen(3000);
PayloadTooLargeError: request entity too large (body-parser limit exceeded)

What this error means

The Express body-parser middleware enforces a maximum request body size to protect against memory exhaustion attacks and prevent inadvertent resource consumption. When a client sends a request exceeding this limit, the middleware rejects it with a 413 (Payload Too Large) HTTP status code. This is a safety mechanism that needs to be adjusted when you legitimately need to accept larger payloads.

Typical symptoms

  • POST or PUT requests fail with 'request entity too large' error
  • JSON API calls that send large objects (images, documents, bulk data) are rejected
  • Only requests with small payloads succeed while large ones fail
  • File upload endpoints return 413 status code
  • The error appears in server logs: 'PayloadTooLargeError'

Common causes

  1. Request payload exceeds the default 100KB limit set by express.json()
  2. Request payload exceeds the default 100KB limit set by express.urlencoded()
  3. Uploading large files without configuring multer's fileSize limit
  4. Sending bulk data in a single API request without adjusting limits
  5. Using older body-parser middleware with default conservative limits

How to fix "PayloadTooLargeError: request entity too large (body-parser limit exceeded)"

1Identify which body-parser middleware is rejecting the request

The error message specifies which middleware is hitting the limit. Most commonly it's express.json() for JSON payloads or express.urlencoded() for form data. Check your Express app initialization.

2Increase the limit in express.json() for JSON payloads

If you're receiving JSON data (most common case), update your middleware configuration:

javascript
const express = require('express');
const app = express();

// Increase JSON payload limit to 50MB
app.use(express.json({ limit: '50mb' }));

app.post('/api/data', (req, res) => {
  // Now accepts payloads up to 50MB
  res.json({ received: req.body });
});

app.listen(3000);

Common limit sizes:
- '100kb' - Default
- '1mb' - Small files and bulk data
- '50mb' - Large images and documents
- '500mb' - Video files (use with caution)

3Increase the limit in express.urlencoded() for form data if applicable

If your endpoint accepts URL-encoded form data, also update this middleware:

javascript
app.use(express.urlencoded({ limit: '50mb', extended: true }));

The extended: true option allows parsing of rich objects and arrays in form data. Use it alongside express.json() to handle both content types.

4For file uploads, configure multer with a fileSize limit

If you're handling file uploads with multer, increase its limits separately:

javascript
const multer = require('multer');

const upload = multer({
  limits: {
    fileSize: 50 * 1024 * 1024, // 50MB in bytes
  },
});

app.post('/upload', upload.single('file'), (req, res) => {
  res.json({ message: 'File uploaded', file: req.file });
});

Note: multer limits are in bytes, not strings like express middleware.

5Test the increased limit with a larger request

Test that your endpoint now accepts larger payloads:

bash
# Test with 10MB of JSON data
curl -X POST http://localhost:3000/api/data \
  -H 'Content-Type: application/json' \
  -d '{"largeArray": [' + Array(1000000).fill(1).join(',') + ']}'

# Or use Node to test programmatically
const data = { largeArray: new Array(100000).fill(1) };
fetch('http://localhost:3000/api/data', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(data),
})
.then(res => res.json())
.then(data => console.log('Success:', data))
.catch(err => console.error('Error:', err));

Advanced notes

Security Considerations: While increasing limits enables larger payloads, set them appropriately for your use case. Unnecessarily large limits consume more server memory and make your application vulnerable to denial-of-service (DoS) attacks. A malicious client could send massive payloads to exhaust memory. Consider:

1. Set a reasonable maximum: If your app only needs 10MB payloads, don't set it to 500MB.
2. Use reverse proxies: Nginx and Apache can enforce limits before traffic reaches your Node app, protecting your application.
3. Rate limiting: Combine with rate limiting middleware to prevent abuse.
4. Monitoring: Log large requests to identify unusual patterns.
5. Validation: Always validate payload structure and sizes on the application side.

TypeScript with Express: If using TypeScript, the syntax is identical—body-parser types are included in express's type definitions.

Alternative Middleware: Some applications use the body-parser npm package directly instead of express's built-in version. The syntax is the same but be aware of version differences.

Frequently asked questions

What does "PayloadTooLargeError: request entity too large (body-parser limit exce" mean?
The Express body-parser middleware enforces a maximum request body size to protect against memory exhaustion attacks and prevent inadvertent resource consumption. When a client sends a request exceeding this limit, the middleware rejects it with a 413 (Payload Too Large) HTTP status code. This is a safety mechanism that needs to be adjusted when you legitimately need to accept larger payloads.
How do I fix "PayloadTooLargeError: request entity too large (body-parser limit exce"?
This error occurs when a POST or PUT request sends more data than Express's body-parser middleware allows. By default, Express limits JSON payloads to 100KB. Increase the limit in your middleware configuration to fix this.
What causes "PayloadTooLargeError: request entity too large (body-parser limit exce"?
Request payload exceeds the default 100KB limit set by express.json() Request payload exceeds the default 100KB limit set by express.urlencoded() Uploading large files without configuring multer's fileSize limit
Is the "PayloadTooLargeError: request entity too large (body-parser limit exce" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading