A module in a nest.js application is used to organize related controllers and service providers into a single logical file.

Simply use the @Module decorator with metadata to the module class to designate what controllers, service providers, and other related resources will be instantiated and used later.

Nest also ships a @Global decorator to allow the module to be shared with other module implicitly.

And nest module system has a feature called Dynamic modules, which enable you to produce customized modules.

The most general useage of dynamic modules is to connect the database:

  • The Dynamic module provides a Connection object. In addition, based on the options passed for the module’s forRoot() static function, the module adds more providers and exports them to the modules where it’s imported.


A controller is responsible for handling incoming HTTP requests, processing them and formulating a proper HTTP response to the client.

A controller groups a set of route handlers - we call them actions - in a class.


A provider is used to encapsulate related business logic and functions.

Dependency Injection(DI) and Inversion of Controller(IoC)



Middleware is used to access the current request, response.

Middleware is executed precedes the route handler.

Exception Filter

Nestjs comes with a built-in general-purpose global exception filter that handles all thrown exceptions in the application.

Specially, it handles exceptions that are of type HttpException or any other exception class that it inherits from HttpException.


A pipe in nest.js is a class annotated with the Injectable decorator and used to transform data from one format to another, to validate route handler parameters and to produce a new data format based on input parameters.

Nest.js comes with two built-in pipes: ValidationPipe, and ParseIntPipe.


A guard is a class annotated with Injectable decorator. It extends CanActivate class and implements the canActivate() method.

It decides whether the route handler executes the current request or not, based on the value returned from the canActivate() method.


interceptor originates from the Aspect-Oriented Programming concepts.

An interceptor manipulates requests and responses.