Kind: Type
Source: packages/platform-express/interfaces/nest-express-body-parser.interface.ts
Part of: Platform Express
Interface defining possible body parser types, to be used with NestExpressApplication.useBodyParser().
NestExpressBodyParserType defines the supported body parser names accepted by NestExpressApplication.useBodyParser(). It lets Express-based Nest applications configure how incoming request bodies are parsed, including JSON, URL-encoded form data, raw buffers, and plain text.
Definition
ts'json' | 'urlencoded' | 'text' | 'raw'
Diagram
mermaidgraph LR A[Incoming HTTP Request] --> B[NestExpressApplication.useBodyParser] B --> C{NestExpressBodyParserType} C --> D[json] C --> E[urlencoded] C --> F[raw] C --> G[text] D --> H[Parsed request body] E --> H F --> H G --> H
Usage
tsimport { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import type { NestExpressApplication } from '@nestjs/platform-express';
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
const parserType: 'json' = 'json';
app.useBodyParser(parserType, {
limit: '10mb',
});
await app.listen(3000);
}
bootstrap();
AI Coding Instructions
- Use this type only with
NestExpressApplication.useBodyParser()in applications running on the Express platform. - Choose
jsonfor JSON APIs,urlencodedfor HTML form submissions,rawfor buffer-based payloads such as webhook signatures, andtextfor plain-text requests. - Configure parsers before starting the application with
app.listen()so request handling uses the intended parser configuration. - Avoid registering conflicting body parsers for the same content type, especially when validating raw webhook payload signatures.
- Keep parser options compatible with Express/body-parser options, such as
limit,type, andextendedfor URL-encoded payloads.
Was this page helpful?