NestJS Interview Questions Hindi mein

NestJS: Scalable Node.js APIs बनाना कोर्स के 20 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

मॉड्यूल 1: शुरुआत करें

1. `nest g resource users` वह क्या करता है जो `nest g controller users` नहीं करता?

  1. यह सिर्फ़ service file बनाता है
  2. यह module, controller, service और DTOs एक साथ बनाता है
  3. यह server को watch mode में चलाता है
जवाब देखें

जवाब: यह module, controller, service और DTOs एक साथ बनाता है

`resource` पूरा feature slice बनाता है, जबकि `controller` सिर्फ़ controller बनाता है।

पाठ: NestJS CLI से सेटअप

2. कौन सी file entry point है जो `NestFactory.create()` call करती है?

  1. app.module.ts
  2. main.ts
  3. app.service.ts
जवाब देखें

जवाब: main.ts

`main.ts` app को bootstrap करती है। `app.module.ts` सिर्फ़ root module है जो उसे दिया जाता है।

पाठ: प्रोजेक्ट संरचना

मॉड्यूल 2: नींव

3. एक provider `providers` में है, पर दूसरे module में inject करने पर error आता है। क्या कमी है?

  1. उसके module को उसे export करना होगा और उस module को import करना होगा
  2. class पर `@Controller()` चाहिए
  3. Nest सिर्फ़ `Service` नाम वाले providers inject करता है
जवाब देखें

जवाब: उसके module को उसे export करना होगा और उस module को import करना होगा

providers अपने module में private रहते हैं जब तक export न हों, और consumer को वह module import करना पड़ता है।

पाठ: Dependency Injection

मॉड्यूल 3: मुख्य अवधारणाएँ

4. Nest provider का default scope क्या है?

  1. हर request पर नया instance
  2. हर injection पर नया instance
  3. एक shared instance (singleton)
जवाब देखें

जवाब: एक shared instance (singleton)

default में Nest एक ही instance बनाकर reuse करता है। request scope अलग से चुनना पड़ता है।

पाठ: Providers और Services

5. request lifecycle में सबसे पहले क्या चलता है?

  1. Guards
  2. Pipes
  3. Middleware
जवाब देखें

जवाब: Middleware

क्रम है middleware, guards, interceptors (before), pipes, handler।

पाठ: Middleware

6. `ValidationPipe` default में unknown properties reject नहीं करता। कौन सा option उन्हें हटाता है?

  1. `whitelist: true`
  2. `transform: false`
  3. `skipMissingProperties: true`
जवाब देखें

जवाब: `whitelist: true`

`whitelist: true` बिना validation decorators वाली properties हटाता है; `forbidNonWhitelisted` उन्हें error बनाता है।

पाठ: Pipes और Validation

7. exception filter पर बिना arguments वाला `@Catch()` क्या पकड़ता है?

  1. सिर्फ़ HttpException
  2. हर thrown exception
  3. सिर्फ़ validation errors
जवाब देखें

जवाब: हर thrown exception

खाली `@Catch()` किसी भी exception type के लिए catch-all filter है।

पाठ: Exception Handling

मॉड्यूल 4: डेटाबेस और डेटा

8. database हाथ से बदलने की जगह migration क्यों बनाएँ?

  1. migrations queries तेज़ करते हैं
  2. बदलाव versioned, reviewable और हर environment में दोहराने योग्य होते हैं
  3. TypeORM manual SQL मना करता है
जवाब देखें

जवाब: बदलाव versioned, reviewable और हर environment में दोहराने योग्य होते हैं

migration files git में रहती हैं और dev, staging, prod में एक जैसे चलती हैं।

पाठ: Migrations

मॉड्यूल 5: डिज़ाइन और पैटर्न

9. `new Logger(UsersService.name)` क्यों बनाते हैं?

  1. यह class का नाम log context में जोड़ता है
  2. यह console output बंद करता है
  3. यह logs file में लिखता है
जवाब देखें

जवाब: यह class का नाम log context में जोड़ता है

context label बताता है कि हर line किस class से आई।

पाठ: Logging

10. TTL के भीतर दूसरी identical request पर `@UseInterceptors(CacheInterceptor)` वाले GET route का क्या होता है?

  1. handler फिर चलता है और cache overwrite करता है
  2. handler चलाए बिना cached response लौटता है
  3. हमेशा 304 लौटता है
जवाब देखें

जवाब: handler चलाए बिना cached response लौटता है

cache hit handler को छोड़ देता है। सिर्फ़ GET responses अपने आप cache होते हैं।

पाठ: Caching

मॉड्यूल 6: प्रैक्टिस और Deployment

11. `Test.createTestingModule` में असली service को fake से कैसे बदलते हैं?

  1. `.overrideProvider(Service).useValue(fake)`
  2. service file delete करके
  3. `NODE_ENV=fake` set करके
जवाब देखें

जवाब: `.overrideProvider(Service).useValue(fake)`

`overrideProvider` dependency को सिर्फ़ test module के भीतर बदलता है।

पाठ: Testing

12. Nest app के लिए multi-stage Dockerfile क्यों?

  1. दो servers चलाने के लिए
  2. एक stage में TypeScript compile करके सिर्फ़ dist और prod dependencies भेजने के लिए
  3. Node की ज़रूरत हटाने के लिए
जवाब देखें

जवाब: एक stage में TypeScript compile करके सिर्फ़ dist और prod dependencies भेजने के लिए

final image में devDependencies और sources नहीं होते, इसलिए छोटी होती है।

पाठ: Docker Integration

मॉड्यूल 10: Revision और Resources

13. NestJS module क्या करता है?

  1. Compiles TypeScript
  2. Opens database connections only
  3. Groups related controllers and providers
  4. Replaces Express
जवाब देखें

जवाब: Groups related controllers and providers

Modules Nest app में व्यवस्था की इकाई हैं।

पाठ: मुख्य Takeaways

14. Controller में services आमतौर पर कैसे मिलती हैं?

  1. new Service()
  2. Global variables
  3. require() at runtime
  4. Constructor dependency injection
जवाब देखें

जवाब: Constructor dependency injection

Nest का IoC container providers आपके लिए inject करता है।

पाठ: मुख्य Takeaways

15. कौन-सा component आने वाले data को validate और transform करता है?

  1. Pipe
  2. Guard
  3. Filter
  4. Module
जवाब देखें

जवाब: Pipe

ValidationPipe handler से पहले DTOs जाँचता है।

पाठ: मुख्य Takeaways

16. कौन-सा component तय करता है कि request आगे जा सकती है (जैसे authorization)?

  1. Pipe
  2. Guard
  3. Interceptor
  4. Entity
जवाब देखें

जवाब: Guard

Guards CanActivate लागू करते हैं और अनुमति देते या रोकते हैं।

पाठ: मुख्य Takeaways

17. Request lifecycle का सही क्रम क्या है?

  1. Pipes, Guards, Middleware, Handler
  2. Handler, Pipes, Guards
  3. Middleware, Guards, Interceptors, Pipes, Handler
  4. Guards, Handler, Middleware
जवाब देखें

जवाब: Middleware, Guards, Interceptors, Pipes, Handler

Interceptors pipes से पहले और handler के बाद फिर चलते हैं।

पाठ: मुख्य Takeaways

18. ORMs में N+1 कौन-सी समस्या बताता है?

  1. Too many migrations
  2. Too many modules
  3. Slow compilation
  4. One query per related row instead of a join or batch
जवाब देखें

जवाब: One query per related row instead of a join or batch

इससे बचने के लिए relations को join या batch से load करें।

पाठ: मुख्य Takeaways

19. TypeORM में database schema को कौन-सा tool version करता है?

  1. Migrations
  2. Interceptors
  3. Pipes
  4. Decorators
जवाब देखें

जवाब: Migrations

Migrations schema बदलाव record और replay करते हैं।

पाठ: मुख्य Takeaways

20. NestJS के लिए multi-stage Docker build क्यों उपयोग करें?

  1. Faster TypeScript
  2. Smaller final image with only runtime files
  3. It is required by Nest
  4. To skip tests
जवाब देखें

जवाब: Smaller final image with only runtime files

Build tools builder stage में रहते हैं; अंतिम image हल्की रहती है।

पाठ: मुख्य Takeaways

← कोर्स पर वापस जाएँ