Fastify Interview Questions Hindi mein

Fastify: High-Performance Node.js APIs बनाना कोर्स के 22 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

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

1. Fastify async/await का उपयोग क्यों करता है?

  1. यह Node.js द्वारा आवश्यक है
  2. Callbacks का उपयोग हटा दिया गया है
  3. I/O operations को साफ-साफ handle करने और प्रदर्शन बनाए रखने के लिए
  4. यह server को single-use बनाता है
जवाब देखें

जवाब: I/O operations को साफ-साफ handle करने और प्रदर्शन बनाए रखने के लिए

Fastify async/await पर बना है ताकि asynchronous operations को efficiently handle कर सके और non-blocking event loop को साफ रखे।

पाठ: आपका पहला सर्वर

मॉड्यूल 2: आधार

2. कौन सा एक chain में status code set करके JSON भेजता है?

  1. `reply.code(201).send({id: 1})`
  2. `request.code(201)`
  3. `reply.json(201)`
जवाब देखें

जवाब: `reply.code(201).send({id: 1})`

`reply.code()` reply ही लौटाता है, इसलिए `.send()` chain हो जाता है।

पाठ: Request और Reply ऑब्जेक्ट

3. plugin function को पहले argument में क्या मिलता है?

  1. Node का http server
  2. एक Fastify instance (encapsulated) और options
  3. सिर्फ़ options object
जवाब देखें

जवाब: एक Fastify instance (encapsulated) और options

signature `(instance, opts)` है, और async न हो तो `done` भी।

पाठ: प्लगइन और डेकोरेटर

मॉड्यूल 3: कोर रूटिंग और हैंडलर

4. किसी resource को आंशिक रूप से अपडेट करने के लिए कौन-सी HTTP method का उपयोग किया जाता है?

  1. PUT
  2. POST
  3. DELETE
  4. PATCH
जवाब देखें

जवाब: PATCH

PATCH आंशिक updates के लिए है; PUT पूरे resource को replace करता है।

पाठ: बेसिक रूटिंग

मॉड्यूल 4: डेटा हैंडलिंग और वैलिडेशन

5. response schema Fastify को तेज़ क्यों बनाता है?

  1. यह database cache करता है
  2. यह generic JSON.stringify की जगह specialised serializer compile करता है
  3. यह logging बंद करता है
जवाब देखें

जवाब: यह generic JSON.stringify की जगह specialised serializer compile करता है

fast-json-stringify schema से serialization code बनाता है, और undeclared fields हटा भी देता है।

पाठ: JSON Schema और वैलिडेशन

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

6. कौन-सा hook validation के बाद लेकिन handler से पहले चलता है?

  1. preHandler
  2. onRequest
  3. preValidation
  4. onSend
जवाब देखें

जवाब: preHandler

preHandler validation के बाद और route handler से पहले चलता है। इसे auth checks या last-minute data preparation के लिए उपयोग करें।

पाठ: Lifecycle Hooks

7. body parse होने से पहले कौन सा hook चलता है?

  1. preHandler
  2. onRequest
  3. onSend
जवाब देखें

जवाब: onRequest

क्रम: onRequest, preParsing, preValidation, preHandler। body preValidation से उपलब्ध होती है।

पाठ: Lifecycle Hooks

8. plugin का decorator parent instance को दिखाने के लिए क्या करें?

  1. plugin का नाम `global` रखें
  2. इसे `fastify-plugin` से wrap करें
  3. `decorate` दो बार call करें
जवाब देखें

जवाब: इसे `fastify-plugin` से wrap करें

`fastify-plugin` encapsulation हटा देता है, इसलिए decorators और hooks parent पर लागू होते हैं।

पाठ: Encapsulation और Scope

मॉड्यूल 6: व्यावहारिक कार्यान्वयन

9. unit tests में server चलाकर fetch करने की जगह `app.inject()` क्यों बेहतर है?

  1. यह तेज़ है और free port नहीं चाहिए
  2. यह सारे hooks छोड़ देता है
  3. यह सिर्फ़ POST के लिए चलता है
जवाब देखें

जवाब: यह तेज़ है और free port नहीं चाहिए

inject पूरा lifecycle in-process चलाता है, इसलिए hooks और validation लागू रहते हैं।

पाठ: Routes को Test करना

मॉड्यूल 7: गुणवत्ता और विश्वसनीयता

10. handler में uncaught `throw new Error('x')` पर Fastify default में कौन सा status देता है?

  1. 400
  2. 500
  3. 200
जवाब देखें

जवाब: 500

statusCode के बिना errors 500 Internal Server Error बनते हैं।

पाठ: Error Handling

11. built-in Pino logger कैसे चालू करते हैं?

  1. `Fastify({ logger: true })`
  2. सिर्फ़ `npm i pino`
  3. यह हमेशा चालू रहता है
जवाब देखें

जवाब: `Fastify({ logger: true })`

logging default में बंद है; `logger: true` Pino को per-request ids के साथ चालू करता है।

पाठ: Logging

मॉड्यूल 10: Best Practices और Interview

12. Fastify Express से तेज़ क्यों है?

  1. यह एक अलग प्रोग्रामिंग भाषा का उपयोग करता है
  2. यह object pooling, efficient routing, और built-in validation के माध्यम से कम overhead रखता है
  3. यह middleware को support नहीं करता
  4. यह केवल browser में चलता है
जवाब देखें

जवाब: यह object pooling, efficient routing, और built-in validation के माध्यम से कम overhead रखता है

Fastify request/reply objects को reuse करता है, trie-based router के साथ routing को optimize करता है, और JSON Schema के साथ input को validate करता है—सभी प्रदर्शन के लिए डिज़ाइन किए गए हैं।

पाठ: Interview प्रश्न और सुझाव

13. Fastify plugins का उद्देश्य क्या है?

  1. Routes में CSS styling जोड़ने के लिए
  2. Express middleware को replace करने के लिए
  3. Functionality (auth, DB, logging) को encapsulate और routes में reuse करने के लिए
  4. केवल HTML templates बनाने के लिए
जवाब देखें

जवाब: Functionality (auth, DB, logging) को encapsulate और routes में reuse करने के लिए

Plugins modular, maintainable code को enable करते हैं concerns को separate करके और reusable components को app में register करने की अनुमति देते हैं।

पाठ: Interview प्रश्न और सुझाव

14. Fastify route handlers में async/await को कैसे handle करता है?

  1. यह उन्हें automatically try/catch में लपेटता है
  2. Async handlers समर्थित नहीं हैं
  3. इसके लिए manual promise chains चाहिए
  4. यह rejected promises को पकड़ता है और errors को error handler में pass करता है
जवाब देखें

जवाब: यह rejected promises को पकड़ता है और errors को error handler में pass करता है

Fastify async/await पर बना है और automatically rejected promises को पकड़ता है, उन्हें setErrorHandler में भेजता है।

पाठ: Interview प्रश्न और सुझाव

15. कौन-सा Fastify method बिना असली server के request भेजता है?

  1. fastify.listen()
  2. fastify.close()
  3. fastify.inject()
  4. fastify.log()
जवाब देखें

जवाब: fastify.inject()

inject तेज़ tests के लिए HTTP requests का अनुकरण करता है।

पाठ: Interview प्रश्न और सुझाव

17. Response schema क्या सुधारता है?

  1. Serialization speed and data safety
  2. CSS size
  3. Git history
  4. DNS lookups
जवाब देखें

जवाब: Serialization speed and data safety

केवल सूचीबद्ध fields serialize होते हैं।

पाठ: Interview प्रश्न और सुझाव

18. कौन-सा lifecycle क्रम सही है?

  1. preHandler, onRequest, onSend
  2. onRequest, preValidation, preHandler, onSend
  3. onSend, onRequest
  4. preValidation, onRequest
जवाब देखें

जवाब: onRequest, preValidation, preHandler, onSend

हर request के लिए hooks निर्धारित क्रम में चलते हैं।

पाठ: Interview प्रश्न और सुझाव

19. Plugin encapsulation क्या देता है?

  1. Global variables
  2. Faster CPU
  3. Scoped decorators, hooks and routes
  4. Automatic HTTPS
जवाब देखें

जवाब: Scoped decorators, hooks and routes

Child plugin के बदलाव sibling plugins तक नहीं पहुँचते।

पाठ: Interview प्रश्न और सुझाव

20. कौन-सा plugin multipart file uploads संभालता है?

  1. @fastify/cors
  2. @fastify/jwt
  3. @fastify/helmet
  4. @fastify/multipart
जवाब देखें

जवाब: @fastify/multipart

यह multipart/form-data parse करता है।

पाठ: Interview प्रश्न और सुझाव

21. Scale करते समय Fastify app को stateless क्यों रखें?

  1. Any instance can serve any request
  2. It uses less RAM
  3. It disables logging
  4. It avoids HTTPS
जवाब देखें

जवाब: Any instance can serve any request

साझा state Redis या database में रहनी चाहिए।

पाठ: Interview प्रश्न और सुझाव

22. कौन-सा plugin सुरक्षात्मक HTTP headers जोड़ता है?

  1. @fastify/static
  2. @fastify/helmet
  3. @fastify/multipart
  4. @fastify/jwt
जवाब देखें

जवाब: @fastify/helmet

Helmet आम security headers सेट करता है।

पाठ: Interview प्रश्न और सुझाव

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