- NodeJS: starting from version v20.13.1 (recommended latest)
- NPM package manager: starting from version 10.5.2 (recommended latest)
- Running PostgreSQL Server: starting from version 16.2 (recommended latest)
- Clone the repo
- Create empty PostgreSQL database
- Copy
.env.example
into a.env
file and fill its own values cd
into the project- Run
npm install -D
to install the dependencies - Run
npm run build
to build - Run
npm run migration:run
to migrate typeorm migrations src/app/database/ - Run
npm run start:dev
to run your dev server
- controllers/ (Route Handling)
- dto/ (Data Transfer Object)
- repository/ (DB logic)
- service/ (Business Logic)
contains globally used things like:
- database/ table migrations
- decorators/ (custom decorators)
- exception-filter/ (http.exception-filter.ts => unify error, exception shape)
- interceptor/ (http-response.interceptor.ts => unify response shape)
- guard/ (auth.guard.ts => handle auth)
- pipe/ (data transform)
- config.ts (export, register diff validated app class based configs)
- app.module.ts (handle dependency injection for diff modules)
you don't need to create /common/ feature/ shared/ DatabaseModule/ ConfigModule/ ... etc
this makes it complicated and very nested for example
why implement ConfigModule
?
NestJS provide you with a built-in one
why you create mediator and you have AppModule
?
you should utilize forRootAsync()
& registerAsync()
methods
- Persona data like user, (admin can be added)
- Authentication, Authorization
- Book
- Author
- Genre
- Modules Communicate to each others using
AppModule (Mediator)
- example:
BookStoreModule > BooksController
usesAppModule > AuthGuard
and if you checkBookStoreModule
it doesn't know aboutAuthModule
this makes ability to later on change the code insideAuthGuard
to utilize External Auth Service likeKeycloak
easily


you can change default status code to SUCCESS: 200
at the src/app/interceptor/http-response.interceptor.ts
{
status: bool,
statusCode": number,
message": string,
data?: any, //response data
errors?: [] //validation errors
}
available Status/Http codes:
- 200: Success (default)
- 204: No Content
- 400: Bad Request (validation)
- 401: Unauthorized
- 404: Not Found
- 500: Internal Server Error