Nest: How to set limit value for jsonParser

Created on 27 Mar 2018  路  5Comments  路  Source: nestjs/nest

I'm submitting a


[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

jsonParser use defualt limit value

Expected behavior

i want to custom limit value in jsonParser

Environment


Nest version: 4.6.1

For Tooling issues:

  • Node version: 9.6.0
  • Platform: Linux
question 馃檶

Most helpful comment

Actually, this should be enough:

import { json } from 'body-parser';
//////
const app = await NestFactory.create(AppModule);
app.use(json({ limit: '50mb' // edit this }))
await app.listen(3000);

All 5 comments

this issue should be asked in Stackoverflow in #nestjs tag.
but anyway, here is an example to achieve this,

in your bootstrap function in main.ts

...
import { json } from 'body-parser';
...
  const instance = express();
  instance.use(json({ limit: '50mb' // edit this }));
  const app = await NestFactory.create(AppModule, instance, {
    bodyParser: false, // tells nest: don't use your bodyParser, we will take care of it. 
  });
...
  await app.listen(3000);

Actually, this should be enough:

import { json } from 'body-parser';
//////
const app = await NestFactory.create(AppModule);
app.use(json({ limit: '50mb' // edit this }))
await app.listen(3000);

@shekohex in package @nestjs/core, it provider support with body parser, but could not configuration it, just like set limit value, i want to add configuration support for these

@twilroad I have posted above how to do that. When you apply body-parser middleware with your custom configuration, this one built-in nest won't be applied again.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artaommahe picture artaommahe  路  3Comments

janckerchen picture janckerchen  路  3Comments

menme95 picture menme95  路  3Comments

mishelashala picture mishelashala  路  3Comments

tronginc picture tronginc  路  3Comments