0
0
NestJSframework~20 mins

Module decorator and metadata in NestJS - Mini Project: Build & Apply

Choose your learning style9 modes available
NestJS Module Decorator and Metadata
📖 Scenario: You are building a simple NestJS application that organizes features into modules. Modules help group related controllers and providers together.
🎯 Goal: Create a NestJS module using the @Module decorator. Add controllers and providers metadata to the module to organize your app structure.
📋 What You'll Learn
Create a module class named AppModule
Use the @Module decorator on AppModule
Add a controller named AppController to the module metadata
Add a provider named AppService to the module metadata
💡 Why This Matters
🌍 Real World
Modules in NestJS help organize code by grouping related controllers and services, making large apps easier to manage.
💼 Career
Understanding module decorators and metadata is essential for building scalable backend applications with NestJS, a popular Node.js framework.
Progress0 / 4 steps
1
Create the AppModule class
Create an empty class named AppModule in your file.
NestJS
Need a hint?

Use the class keyword followed by AppModule and empty curly braces.

2
Import Module decorator and add it to AppModule
Import Module from @nestjs/common and add the @Module decorator above the AppModule class.
NestJS
Need a hint?

Use @Module({}) just before the class declaration.

3
Add controllers metadata with AppController
Inside the @Module decorator, add a controllers array with AppController as its only element.
NestJS
Need a hint?

Write controllers: [AppController] inside the decorator object.

4
Add providers metadata with AppService
Add a providers array inside the @Module decorator with AppService as its only element.
NestJS
Need a hint?

Add providers: [AppService] inside the decorator object after controllers.