Kind: Interface
Source: packages/platform-express/interfaces/nest-express-body-parser-options.interface.ts
Part of: Platform Express
Type alias to keep compatibility with
NestExpressBodyParserOptions defines the supported configuration for body parsing in the NestJS Express platform. It mirrors the relevant Express/body-parser options to preserve compatibility when configuring how incoming request bodies are inflated, size-limited, and matched by content type.
Properties
| Property | Type |
|---|---|
inflate | `boolean |
limit | `number |
type | `string |
Diagram
mermaidgraph LR A[NestExpressBodyParserOptions] --> B[inflate] A --> C[limit] A --> D[type] B --> B1[Enable or disable compressed body inflation] C --> C1[Maximum accepted request body size] D --> D1[Content type string, array, or request predicate] A --> E[Express body parser configuration]
Usage
tsimport { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import type { NestExpressBodyParserOptions } from '@nestjs/platform-express';
async function bootstrap() {
const bodyParserOptions: NestExpressBodyParserOptions = {
inflate: true,
limit: '2mb',
type: ['application/json', 'application/*+json'],
};
const app = await NestFactory.create(AppModule, {
bodyParser: false,
});
app.useBodyParser('json', bodyParserOptions);
await app.listen(3000);
}
bootstrap();
AI Coding Instructions
- Use this interface when passing body-parser-compatible options to Nest's Express platform APIs, such as
app.useBodyParser(). - Set
limitto a conservative value (for example,'1mb'or'2mb') to reduce the risk of oversized request payloads. - Use
typeto restrict parsing to expected content types; a predicate receives the Node.jsIncomingMessage. - Keep
inflateenabled unless the application explicitly needs to reject compressed request bodies. - Do not assume these options apply to every parser type; ensure the selected parser and Express integration support the configured behavior.
Was this page helpful?