I\'m using Node.js and express.
I would like to limit the HTTP request size. Let\'s say, if someone sends me a HTTP request more than 2 MB then I stop the request r
Use raw-body. Most middleware (like limit) is no longer bundled with Express and must be installed separately. Here's an example.
var getRawBody = require('raw-body')
app.use(function (req, res, next) {
getRawBody(
stream = req,
options = {
length: req.headers['content-length'],
limit: '100mb',
},
callback = function (err, reslt) {
if (err) {
return next(err)
}
next();
console.log(req)
})
})
app.useExpress no longer allows you to explicitly set the limit using the traditional bundled middleware as show below.
app.use(express.limit('4M'));