ParseIntPipe
Parses and validates a route or query value as an integer.
Syntax
new ParseIntPipe(options?: { errorHttpStatusCode }) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
options | object | No | Optional errorHttpStatusCode and custom exceptionFactory. |
Returns
number — The parsed integer passed to the handler.
Throws
BadRequestException— Thrown when the value cannot be parsed as an integer.
Examples
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
@Controller('cats')
export class CatsController {
@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {
return { id };
}
}
Notes
Use the class directly for default behavior or `new ParseIntPipe({...})`
to customize the error status. Pair with DefaultValuePipe to provide a
fallback for optional query parameters.