- Nest. JS is a framework that helps build NodeJS server-side applications.
- The Nest framework uses TypeScript, allowing developers to build highly scalable and testable applications.
- It has its own rules and is not only for backend development.
- The framework is DDD-friendly, event-sourced, and offers microservice architecture
- NestJs uses it as a starting point to resolve the application structure of the relationship.
- The benefit of using NestJs is that you can define your types, validation rules, and documentation in dependency in the same block of code.
Three main components:
- Controllers: Controllers handle the request and return an appropriate response
- Providers: Providers are fundamental to NestJs. The provider can be injected as a dependency to create relationships between objects.
- Modules: Modules are intended to encapsulate a closely related set of capabilities. Each application has a root module.
Modules
A module is a class annotated with a @Modules() decorator. The @module() decorator provides metadata the Nest marks use to organize the application structure. Each application has at least one module
A module is a class annotated with a @Modules() decorator. The @module() decorator provides metadata the Nest marks use to organize the application structure.
Each application has at least one module
Create module:
nest g module users
@module({
imports:[ ],
controllers:[ ],
providers:[ ]
})
export class UserModule{}
Controllers
The controller is responsible for handling the incoming request and returning responses to the client.
@controller(‘user’)
export class UserController{
//add user
@Post(‘/add’)
addBook():string{
return “Add book”
}
}
Providers
Anything that can be injected as a dependency
Constructor (private userService:UserService) { }