Challenge - 5 Problems
NestJS Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why was NestJS created?
NestJS was created to solve which main problem in Node.js backend development?
Attempts:
2 left
💡 Hint
Think about what developers struggle with when building large backend apps in Node.js.
✗ Incorrect
NestJS was designed to bring a clear structure and modularity to Node.js backend apps, making them easier to build and maintain.
❓ component_behavior
intermediate2:00remaining
What does NestJS provide out of the box?
Which feature is a core part of NestJS that helps developers write clean backend code?
Attempts:
2 left
💡 Hint
Think about how NestJS helps manage how classes get their needed parts.
✗ Incorrect
Dependency injection is a key feature in NestJS that allows classes to receive their dependencies automatically, improving code modularity and testing.
📝 Syntax
advanced2:30remaining
Which code snippet correctly defines a NestJS controller?
Choose the option that shows a valid NestJS controller class with a GET route.
Attempts:
2 left
💡 Hint
Look for correct use of decorators and class syntax.
✗ Incorrect
Option C correctly uses the @Controller and @Get decorators on a class and method, following NestJS syntax.
❓ lifecycle
advanced2:30remaining
When is the NestJS module lifecycle hook 'onModuleInit' called?
At what point in the NestJS application lifecycle does the 'onModuleInit' method run?
Attempts:
2 left
💡 Hint
Think about when initialization logic for a module should run.
✗ Incorrect
'onModuleInit' runs after the module's dependencies are ready but before the app starts accepting requests, allowing setup tasks.
🔧 Debug
expert3:00remaining
Why does this NestJS service fail to inject the dependency?
Given this service code, why will NestJS throw a runtime error about missing dependency?
```typescript
import { Injectable } from '@nestjs/common';
import { CatsRepository } from './cats.repository';
@Injectable()
export class CatsService {
constructor(private catsRepo: CatsRepository) {}
}
```
Options:
Attempts:
2 left
💡 Hint
Check if the dependency class is properly decorated for injection.
✗ Incorrect
For NestJS to inject a class, it must be decorated with @Injectable(). Without it, NestJS does not recognize it as a provider.