Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Controller decorator from NestJS.
NestJS
import { [1] } from '@nestjs/common';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing Module with Controller
Using NestFactory which is for app creation
✗ Incorrect
The Controller decorator is imported from '@nestjs/common' to define a controller in NestJS.
2fill in blank
mediumComplete the code to create a basic controller class named AppController.
NestJS
export class [1]Controller {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated names like Home or Root
Forgetting to export the class
✗ Incorrect
The main controller in a NestJS app is often named AppController.
3fill in blank
hardFix the error in the decorator to define a module with AppController.
NestJS
@Module({
controllers: [[1]Controller],
})
export class AppModule {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a controller name that was not defined
Forgetting to include the controller in the module
✗ Incorrect
The module should list the correct controller name, which is AppController.
4fill in blank
hardFill both blanks to create and start the NestJS application.
NestJS
async function bootstrap() {
const app = await [1].create([2]Module);
await app.listen(3000);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Module instead of AppModule
Using App instead of NestFactory
✗ Incorrect
NestFactory creates the app instance and AppModule is the root module passed to it.
5fill in blank
hardFill in the blanks to define a simple GET route returning 'Hello World!'.
NestJS
@Controller() export class AppController { @[1]() getHello(): string { return [2]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Post instead of @Get
Returning the string without quotes
Using single quotes inconsistently
✗ Incorrect
The @Get() decorator defines a GET route. The method returns the string "Hello World!".