Bird
Raised Fist0
NestJSframework~20 mins

Why NestJS exists - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
NestJS Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why was NestJS created?
NestJS was created to solve which main problem in Node.js backend development?
ATo provide a structured and scalable architecture for building server-side applications
BTo replace JavaScript with a new programming language
CTo simplify database management by removing the need for ORMs
DTo create a frontend framework for building user interfaces
Attempts:
2 left
💡 Hint
Think about what developers struggle with when building large backend apps in Node.js.
❓ component_behavior
intermediate
2:00remaining
What does NestJS provide out of the box?
Which feature is a core part of NestJS that helps developers write clean backend code?
ADependency injection system to manage class dependencies automatically
BBuilt-in frontend templating engine for UI rendering
CAutomatic CSS styling for web pages
DReal-time chat server without any configuration
Attempts:
2 left
💡 Hint
Think about how NestJS helps manage how classes get their needed parts.
📝 Syntax
advanced
2:30remaining
Which code snippet correctly defines a NestJS controller?
Choose the option that shows a valid NestJS controller class with a GET route.
A
import { Controller, Get } from '@nestjs/common'

@Controller('cats')
class CatsController {
  @Get
  findAll() {
    return 'All cats';
  }
}
B
import { Controller, Get } from '@nestjs/common';

@Controller('cats')
export function CatsController() {
  @Get()
  function findAll() {
    return 'Cats list';
  }
}
C
import { Controller, Get } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  @Get()
  findAll() {
    return 'This action returns all cats';
  }
}
D
import { Controller, Get } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  findAll() {
    return 'Cats';
  }
}
Attempts:
2 left
💡 Hint
Look for correct use of decorators and class syntax.
❓ lifecycle
advanced
2:30remaining
When is the NestJS module lifecycle hook 'onModuleInit' called?
At what point in the NestJS application lifecycle does the 'onModuleInit' method run?
AOnly when the application shuts down
BRight after the module's providers have been instantiated but before the app starts listening
CBefore any modules or providers are created
DAfter every HTTP request is handled
Attempts:
2 left
💡 Hint
Think about when initialization logic for a module should run.
🔧 Debug
expert
3: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:
AThe constructor parameter should be public, not private
BCatsService is missing the @Controller decorator
CCatsRepository must be imported from '@nestjs/common' to work
DCatsRepository is not marked with @Injectable(), so NestJS cannot inject it
Attempts:
2 left
💡 Hint
Check if the dependency class is properly decorated for injection.

Practice

(1/5)
1. Why was NestJS created as a framework for backend development?
easy
A. To replace frontend frameworks like React and Angular
B. To create mobile applications easily
C. To only support legacy JavaScript without TypeScript
D. To provide a clear and organized way to build scalable server-side apps

Solution

  1. Step 1: Understand NestJS purpose

    NestJS is designed to help developers build backend applications that are easy to maintain and scale.
  2. Step 2: Compare options with NestJS goals

    Options A, C, and D do not match NestJS's backend focus or modern language support.
  3. Final Answer:

    To provide a clear and organized way to build scalable server-side apps -> Option D
  4. Quick Check:

    Backend clarity and scalability = B [OK]
Hint: NestJS focuses on backend clarity and scalability [OK]
Common Mistakes:
  • Confusing NestJS with frontend frameworks
  • Thinking NestJS only supports old JavaScript
  • Assuming NestJS is for mobile apps
2. Which of the following is the correct way to create a basic NestJS controller?
easy
A. import { Controller, Get } from '@nestjs/common'; @Controller('cats') export class CatsController { @Get() findAll() { return 'This action returns all cats'; } }
B. import { Controller } from 'nestjs'; @Controller('/cats') class Cats { getAll() { return 'Cats list'; } }
C. const controller = require('nestjs').Controller; controller('/cats', () => { return 'Cats'; });
D. import { Controller, Post } from '@nestjs/common'; @Controller('cats') export class CatsController { findAll() { return 'All cats'; } }

Solution

  1. Step 1: Check import and decorator usage

    import { Controller, Get } from '@nestjs/common'; @Controller('cats') export class CatsController { @Get() findAll() { return 'This action returns all cats'; } } correctly imports from '@nestjs/common' and uses @Controller and @Get decorators properly.
  2. Step 2: Verify method and return value

    import { Controller, Get } from '@nestjs/common'; @Controller('cats') export class CatsController { @Get() findAll() { return 'This action returns all cats'; } }'s method findAll returns a string as expected for a GET route. Other options have wrong imports, missing decorators, or wrong HTTP method.
  3. Final Answer:

    Option A code snippet -> Option A
  4. Quick Check:

    Correct decorators and imports = A [OK]
Hint: Look for @Controller and @Get from '@nestjs/common' [OK]
Common Mistakes:
  • Using wrong import paths
  • Missing HTTP method decorators
  • Using require instead of import
3. Consider this NestJS service code:
import { Injectable } from '@nestjs/common';

@Injectable()
export class MathService {
  double(value: number): number {
    return value * 2;
  }
}

const service = new MathService();
console.log(service.double(5));
What will be printed in the console?
medium
A. 10
B. 5
C. undefined
D. Error: Injectable decorator missing

Solution

  1. Step 1: Understand the double method

    The method multiplies the input value by 2, so double(5) returns 10.
  2. Step 2: Check usage of Injectable decorator

    The @Injectable decorator marks the class for NestJS dependency injection but does not affect direct instantiation or method output.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    5 times 2 equals 10 [OK]
Hint: Method doubles input; decorator doesn't block direct use [OK]
Common Mistakes:
  • Thinking @Injectable prevents direct instantiation
  • Expecting undefined return
  • Confusing decorator effects with runtime errors
4. This NestJS controller code has an error:
import { Controller, Get } from '@nestjs/common';

@Controller('dogs')
export class DogsController {
  @Get()
  getDogs() {
    return this.dogs;
  }
}
What is the main problem here?
medium
A. The import statement is wrong
B. The controller is missing a constructor to initialize 'dogs'
C. The @Get decorator is used incorrectly
D. The method getDogs should be async

Solution

  1. Step 1: Identify usage of 'this.dogs'

    The method returns 'this.dogs' but the class does not define or initialize 'dogs'.
  2. Step 2: Check for initialization

    Without a constructor or property assignment, 'this.dogs' is undefined, causing runtime errors.
  3. Final Answer:

    The controller is missing a constructor to initialize 'dogs' -> Option B
  4. Quick Check:

    Undefined property needs initialization [OK]
Hint: Check if all used properties are initialized [OK]
Common Mistakes:
  • Assuming decorators fix property issues
  • Thinking async is required without async code
  • Ignoring missing property initialization
5. You want to build a scalable backend app using NestJS that handles many users and keeps code organized. Which feature of NestJS helps most with this goal?
hard
A. Its use of global variables for shared state
B. Its built-in support for frontend UI components
C. Its modular architecture allowing separation of features into modules
D. Its automatic generation of mobile app code

Solution

  1. Step 1: Identify scalability needs

    Scalable apps need clear separation of concerns and organized code structure.
  2. Step 2: Match NestJS features to needs

    NestJS modules let you group related code, making it easier to maintain and scale. Other options do not support backend scalability.
  3. Final Answer:

    Its modular architecture allowing separation of features into modules -> Option C
  4. Quick Check:

    Modular design = scalable backend [OK]
Hint: Modular design is key for scalable backend apps [OK]
Common Mistakes:
  • Confusing backend with frontend features
  • Thinking NestJS generates mobile code
  • Using global variables instead of modules
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard