पाठ 29 / 30

npm पर Publish करना

npm registry पर package publish करें: unique name, versioning, npm login, bin field और npm publish।

publish के लिए क्या चाहिए

एक अद्वितीय name, एक version, npm login, और अगर यह CLI टूल है तो bin फ़ील्ड — फिर npm publish इसे registry पर अपलोड करता है।

publish वर्कफ़्लो

हर publish से पहले वर्ज़न बढ़ाएँ — npm एक ही वर्ज़न नंबर को दोबारा publish करने से मना कर देता है।

npm login
npm version patch      # 1.0.0 -> 1.0.1
npm publish

त्वरित जाँच: अपडेट publish करने से पहले npm version patch क्यों महत्वपूर्ण है?

  • npm उस वर्ज़न नंबर को publish करने से मना कर देता है जो registry पर पहले से मौजूद है
  • यह कोड को compile करता है
  • यह पिछले वर्ज़न को हटा देता है
  • यह code अपने-आप upload करता है
Answer

npm उस वर्ज़न नंबर को publish करने से मना कर देता है जो registry पर पहले से मौजूद है — Registry हर वर्ज़न को अपरिवर्तनीय मानता है — नए बदलाव publish करने के लिए आपको नंबर बढ़ाना होगा।

अंतिम क्विज़ 1/8

अंतिम क्विज़

त्वरित जाँच: Node एक thread से कई connections कैसे संभाल पाता है?

  • One thread per request
  • Compiling to C++
  • Non-blocking I/O and the event loop
  • A built-in database
Answer

Non-blocking I/O and the event loop — Waiting I/O आगे सौंप दिया जाता है जबकि loop दूसरा काम करता है।

अंतिम क्विज़ 2/8

अंतिम क्विज़

त्वरित जाँच: package.json का कौन-सा field ES module syntax चालू करता है?

  • "main": "esm"
  • "es": true
  • "import": "all"
  • "type": "module"
Answer

"type": "module" — type को module सेट करें (या .mjs उपयोग करें)।

अंतिम क्विज़ 3/8

अंतिम क्विज़

त्वरित जाँच: ^4.19.2 क्या अनुमति देता है?

  • Minor and patch updates below 5.0.0
  • Only patch updates
  • Major updates
  • No updates
Answer

Minor and patch updates below 5.0.0 — Caret उसी major version के भीतर संगत updates की अनुमति देता है।

अंतिम क्विज़ 4/8

अंतिम क्विज़

त्वरित जाँच: Server handler में fs/promises क्यों उपयोग करें?

  • It is shorter
  • It does not block the event loop
  • It encrypts files
  • It needs no import
Answer

It does not block the event loop — Async file calls से अन्य requests चलती रहती हैं।

अंतिम क्विज़ 5/8

अंतिम क्विज़

त्वरित जाँच: कौन-सा method readable stream को writable stream से backpressure के साथ जोड़ता है?

  • push
  • emit
  • pipe (or pipeline)
  • spawn
Answer

pipe (or pipeline) — pipe और stream.pipeline flow control आपके लिए संभालते हैं।

अंतिम क्विज़ 6/8

अंतिम क्विज़

त्वरित जाँच: स्वतंत्र async calls को एक साथ कैसे चलाएँ?

  • Await them one by one
  • setTimeout
  • process.exit
  • Promise.all
Answer

Promise.all — Promise.all उन्हें concurrently चलाता है और सबके पूरा होने का इंतजार करता है।

अंतिम क्विज़ 7/8

अंतिम क्विज़

त्वरित जाँच: uncaughtException के बाद क्या करना चाहिए?

  • Log it and exit the process
  • Ignore it
  • Retry forever
  • Delete node_modules
Answer

Log it and exit the process — Process अज्ञात state में हो सकता है, इसलिए exit करें और supervisor को restart करने दें।

अंतिम क्विज़ 8/8

अंतिम क्विज़

त्वरित जाँच: कौन-सा Node module CPU-भारी काम को main thread से बाहर ले जाता है?

  • path
  • worker_threads
  • os
  • dotenv
Answer

worker_threads — Worker threads event loop को responsive रखते हैं।