Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Express: limit request size

To limit the request size to 123 bytes, I use the following which works fine:

app.use(bodyParser.urlencoded({
    extended: true,
    limit: 123
}));

To parse all requests except for "/specialRequest", I use the following which works fine as well:

app.use(/^(?!\/specialRequest)/,bodyParser.urlencoded({
    extended: true
}));

But I fail to limit the request size of all requests to 123 and parse all requests except for "/specialRequest". Here is my current code:

app.use(/^(?!\/specialRequest)/,bodyParser.urlencoded({
    extended: true,
    limit: 123
}));

However, this only limits the requests size for requests different than "/specialRequest". How can I limit the request size of all requests to 123 and parse all requests except for "/specialRequest"?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want the request body for /specialRequest to be limited in size but not parsed, you can use bodyParser.raw(). In that case, req.body will be a Buffer instance that contains the request body as-is (unparsed, although it will be inflated if it was presented as gzipped or deflated data; this behaviour can be disabled through its options).

You need to declare it before you insert the bodyParser.urlencoded() middleware:

app.post('/specialRequest', bodyParser.raw({ limit : 123, type : '*/*' }), function(req, res) {
  ...
});

app.use(bodyParser.urlencoded({
    extended: true,
    limit: 123
}));
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!