To fix the ‘Error: request entity too large’ in Express, we can set the limit
option when we add body-parser
into our Express app.
For instance, we can write:
const express = require('express')
const app = express()
const port = 3000
const bodyParser = require('body-parser')
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.post('/', (req, res) => {
res.json(req.body)
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
to set the max size of JSON and URL encoded request data to 50MB by setting limit
to '50mb'
.