Overview
@nestjsx/crud is the core package of the NestJS CRUD framework. It provides decorators, controllers, and services that enable you to quickly build RESTful CRUD APIs with minimal boilerplate code.
What It Does
This package is the foundation of the CRUD framework and provides:@Crud()decorator - Automatically generates CRUD endpoints for your controllers- Base service abstractions - Provides
CrudServiceinterface for implementing custom services - Helper decorators - Additional decorators like
@ParsedRequest,@ParsedBody,@Override, and more - Request interceptors - Built-in interceptors for request parsing and validation
- Global configuration - Configure CRUD behavior across your entire application
- Route customization - Fine-grained control over which routes are generated and how they behave
Key Features
Automatic Endpoint Generation
With a single decorator, generate all standard CRUD endpoints:GET /resource- Get many resources (with filtering, pagination, sorting)GET /resource/:id- Get one resource by IDPOST /resource- Create a new resourcePATCH /resource/:id- Update a resourcePUT /resource/:id- Replace a resourceDELETE /resource/:id- Delete a resource
Flexible Configuration
Configure routes globally or per-controller:- Enable/disable specific routes
- Customize validation
- Set default query parameters
- Configure authentication and authorization
- Add custom route options
Database Agnostic
The core package is database-agnostic. You can implement theCrudService interface for any database or ORM, or use provided implementations like @nestjsx/crud-typeorm.
Main Exports
The package exports the following key items:Decorators
Crud- Main decorator for generating CRUD routesCrudAuth- Authentication configuration decoratorOverride- Override default route handlersParsedRequest- Access parsed request queryParsedBody- Access parsed request bodyFeature- Feature-specific actions
Services
CrudService- Abstract service interface
Interfaces & Types
Various TypeScript interfaces and types for configuration and type safety.Module
CrudConfigService- Global configuration service
Dependencies
This package has the following dependencies:@nestjsx/crud-request- Request parsing and validation@nestjsx/util- Utility functionsdeepmerge- Deep merging of configuration objectspluralize- Pluralization of resource names
Peer Dependencies
You’ll also need to install:class-transformer- For object transformationclass-validator- For validation
While this is the core package, you’ll typically want to install a companion package like
@nestjsx/crud-typeorm to handle actual database operations.Use Cases
This package is ideal when you:- Want to rapidly scaffold RESTful CRUD APIs
- Need consistent API endpoints across multiple resources
- Want to reduce boilerplate code in your controllers
- Need built-in support for filtering, pagination, and sorting
- Want automatic Swagger documentation for your CRUD endpoints
Learn More
Installation
Install and configure the package
Quick Start
Build your first CRUD controller