Skip to main content

Prerequisites

Before installing NestJS CRUD, ensure you have:
  • Node.js 14.x or higher
  • An existing NestJS project (v9.x or higher recommended)
  • TypeScript 4.6 or higher
If you don’t have a NestJS project yet, create one using:
npm i -g @nestjs/cli
nest new my-project

Install core packages

NestJS CRUD requires the core package along with class-transformer and class-validator for request validation.
npm install @nestjsx/crud class-transformer class-validator

Install TypeORM integration

To use NestJS CRUD with TypeORM (recommended), install the TypeORM packages:
npm install @nestjsx/crud-typeorm @nestjs/typeorm typeorm

Install database driver

Install the appropriate database driver for your database:
npm install pg

Configure TypeORM

Create or update your TypeORM configuration in your app module:
app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'your_username',
      password: 'your_password',
      database: 'your_database',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true, // Set to false in production
    }),
  ],
})
export class AppModule {}
Set synchronize: false in production environments. Use migrations instead to manage database schema changes.

Optional: Install request builder

If you’re building a frontend application and want type-safe query building, install the request builder package:
npm install @nestjsx/crud-request
The request builder allows you to construct API queries in your client code:
frontend-example.ts
import { RequestQueryBuilder } from '@nestjsx/crud-request';

const query = RequestQueryBuilder.create()
  .setFilter({ field: 'name', operator: '$cont', value: 'Tech' })
  .setLimit(10)
  .sortBy({ field: 'name', order: 'ASC' })
  .query();

// Result: filter=name||$cont||Tech&limit=10&sort=name,ASC
fetch(`/api/companies?${query}`);

Verify installation

Verify that all packages are installed correctly:
npm list @nestjsx/crud @nestjsx/crud-typeorm
You should see output similar to:
[email protected] /path/to/my-project
├── @nestjsx/[email protected]
└── @nestjsx/[email protected]

TypeScript configuration

Ensure your tsconfig.json has the following compiler options enabled:
tsconfig.json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}
These options are required for decorators and metadata reflection to work properly.

Next steps

Quickstart

Now that you have NestJS CRUD installed, follow the quickstart guide to build your first CRUD API in minutes.

Build docs developers (and LLMs) love