What are modules, controllers and services?
Try code in the playgroundUnderstand the concept
Nest modules define feature boundaries and register the controllers and providers that belong to a feature. Controllers handle transport concerns, while services usually contain business rules. This separation makes code easier to reuse and test without tying every decision to HTTP.
Important ideas
-
A module groups a feature and declares its dependencies.
-
A controller handles HTTP input and responses.
-
A service holds business logic; keep controllers small.
-
Keep database and business operations out of large controllers; a service can also be called by a job or scheduled task.
Can you explain it without the notes?
What are modules, controllers and services?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Nest modules define feature boundaries and register the controllers and providers that belong to a feature. Controllers handle transport concerns, while services usually contain business rules. This separation makes code easier to reuse and test without tying every decision to HTTP.
Turn this concept into a clear answer.
- A module describes dependency visibility; it is more than a folder that holds related files.
Adapted from 03_NESTJS.md · “What are modules, controllers and services?”. Examples are study fragments; framework behavior can depend on your version.