Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - controlling the size of a POST request

Tags:

http

post

node.js

I have a program in Node.JS, using Express. When I do a POST request to this program, what is the maximum accepted size for the data in the request? Is there any way to set this size?

like image 567
Leprosy Avatar asked Sep 06 '25 03:09

Leprosy


1 Answers

If you are using Express, you can use the limit middleware: http://senchalabs.github.com/connect/middleware-limit.html

If you are interested in it's implementation, it does something like this:

// limit
req.on('data', function(chunk){
  received += chunk.length;
  if (received > bytes) deny();
});

For more details check the code on github: https://github.com/senchalabs/connect/blob/master/lib/middleware/limit.js

like image 61
alessioalex Avatar answered Sep 08 '25 10:09

alessioalex