Skip to content

NestExpressBodyParserOptions

reference
1 min readUpdated

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

PropertyType
inflate`boolean
limit`number
type`string

Diagram

mermaid
graph 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

ts
import { 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 limit to a conservative value (for example, '1mb' or '2mb') to reduce the risk of oversized request payloads.
  • Use type to restrict parsing to expected content types; a predicate receives the Node.js IncomingMessage.
  • Keep inflate enabled 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?

Download as PDF
NestExpressBodyParserOptions — NestJS head-to-head