Generated App

nest-cli g app produces a production-ready NestJS project that already follows the nest-extended conventions. This page describes what you get.

Project structure

A generated app wires up the runtime pieces for you:

  • Database + ORM configuration for your chosen adapter
  • ClsModule mounted as middleware for request-scoped user context
  • Soft-delete configuration on NestExtendedModule.forRoot(), which also discovers and wires every @ServiceEvents() class
  • A global exception filter and the null→404 response interceptor
  • A .env with the connection string and JWT_SECRET
  • With --auth: an Auth module and a Users module

Since 1.5.0 generated apps are emitted as CommonJS, and each resource ships a {name}.events.ts alongside its service.

HTTP API

Every resource generated with nest-cli g service exposes standard CRUD routes through the NestController base class:

MethodRouteService callBehaviour
GET/resourcefind(query)Paginated list (supports the query language)
GET/resource/:idget(id, query)Fetch one (404 when missing)
POST/resourcecreate(dto)Create (stamps createdBy)
PATCH/resource/:idpatch(id, dto, query)Update (stamps updatedBy)
DELETE/resource/:idremove(id, query, user)Soft delete (stamps deletedBy)

Why the non-underscore names? They are the event-firing versions of _find / _get / _create / _patch / _remove — identical arguments and return values, but they dispatch to the resource's {name}.events.ts class. See Service Events. Projects generated before 1.5.0 switch over with nest-cli m events.

Auth flow

When generated with --auth, the app includes JWT authentication and a users module with the standard fields (firstName, lastName, email, password, phone, role). Routes are protected by default; mark public endpoints with the @Public() decorator:

cats.controller.ts
import { Public } from '@nest-extended/decorators';
 
@Public()
@Get()
findAll() {
  // accessible without a JWT
}

Error handling

The global exception filter translates database errors into clean HTTP responses:

POST /users  (duplicate email)
→ 400 Bad Request: "A user with this email already exists"
 
GET /cats/:badId
→ 404 Not Found        (via NullResponseInterceptor)

Zod or class-validator errors (depending on the --validator you chose) are returned as structured 400 responses.

Environment variables

.env
# Prisma / TypeORM
DATABASE_URL="postgresql://user:password@localhost:5432/db"
 
# Mongoose
MONGODB_URI="mongodb://localhost:27017/db"
 
# When --auth is enabled
JWT_SECRET="change-me"

Next steps