title: PayloadTooLargeError: request entity too large
body: <p>I got the following error with bodyParser:</p>
  
  <pre><code>PayloadTooLargeError: request entity too large
  at readStream (/root/server/node_modules/raw-body/index.js:155:17)
  at getRawBody (/root/server/node_modules/raw-body/index.js:108:12)
  at read (/root/server/node_modules/body-parser/lib/read.js:77:3)
  at urlencodedParser (/root/server/node_modules/body-parser/lib/types/urlencoded.js:116:5)
  at Layer.handle [as handle_request] (/root/server/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/root/server/node_modules/express/lib/router/index.js:317:13)
  at /root/server/node_modules/express/lib/router/index.js:284:7
  at Function.process_params (/root/server/node_modules/express/lib/router/index.js:335:12)
  at next (/root/server/node_modules/express/lib/router/index.js:275:10)
  at jsonParser (/root/server/node_modules/body-parser/lib/types/json.js:118:7)
  at Layer.handle [as handle_request] (/root/server/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/root/server/node_modules/express/lib/router/index.js:317:13)
  at /root/server/node_modules/express/lib/router/index.js:284:7
  at Function.process_params (/root/server/node_modules/express/lib/router/index.js:335:12)
  at next (/root/server/node_modules/express/lib/router/index.js:275:10)
  at initialize (/root/server/node_modules/passport/lib/middleware/initialize.js:53:5)
  at Layer.handle [as handle_request] (/root/server/node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (/root/server/node_modules/express/lib/router/index.js:317:13)
  at /root/server/node_modules/express/lib/router/index.js:284:7
  at Function.process_params (/root/server/node_modules/express/lib/router/index.js:335:12)
  at next (/root/server/node_modules/express/lib/router/index.js:275:10)
  at jsonParser (/root/server/node_modules/body-parser/lib/types/json.js:118:7)
  </code></pre>
  
  <p>the code is following</p>
  
  <pre><code>const express = require("express");
  const bodyParser = require('body-parser');
  
  function setEntity(req, res) {
     // something....
  }
  
  module.exports = (app) =&gt; {
  
    const router = new express.Router();
  
    app.use(bodyParser.json({limit:'50mb'}));
    app.use(bodyParser.urlencoded({
      extended: true
    }));
  
    router.use('/set/', (req, res) =&gt; {
      setEntity(req, res);
    });
  
    return router;
  };
  </code></pre>
  
  <p>It seems similar to <a href="https://stackoverflow.com/questions/19917401/error-request-entity-too-large">this question</a></p>
  
  <p>So I tried these 3 solutions.</p>
  
  <p>1.</p>
  
  <pre><code>app.use(bodyParser.json({limit: '50mb'}));
  app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>app.use(bodyParser.json({limit: "50mb"}));
  app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>app.use(bodyParser.json({limit:1024*1024*20, type:'application/json'}));
  app.use(bodyParser.urlencoded({extended:true,limit:1024*1024*20,type:'application/x-www-form-urlencoding' }));
  </code></pre>
  
  <p>but the result didn't change.</p>
  
  <p>another setting is like below</p>
  
  <pre><code>nginx has this setting : client_max_body_size 200M;
  data size is under 500kb (json).
  express : 4.15.3
  body-parser : 1.18.2
  </code></pre>
  
  <p>I have no idea why I can't change limit data size.</p>