JavaScript Engine ek program hai jo JavaScript code ko machine code mein convert karke run karta hai. Har web
browser ka apna apna JavaScript engine hota hai. Jaise:
Google Chrome mein V8 engine hota hai.
Firefox mein SpiderMonkey engine hota hai.
Safari mein JavaScriptCore (Nitro) engine hota hai.
Edge mein Chakra engine hota tha, lekin ab V8 engine use hota hai.
Node.js ek open-source, cross-platform JavaScript runtime environment hai jo server-side applications run karne ke liye use hota hai. Iska founder Ryan Dahl tha, jo 2009 mein Node.js ko develop kar raha tha. Node.js Google ke V8 JavaScript engine ka use karta hai jo JavaScript ko machine code mein convert karta hai aur fast execution provide karta hai. V8 engine ko C++ mein likha gaya hai, jisse performance aur speed kaafi improve hoti hai, kyunki C++ low-level language hai jo zyada efficient hoti hai. Nodejs ka use mainly web servers, APIs, real-time applications aur microservices banane ke liye hota hai.
Blocking (Synchronous): Blocking code wo hota hai jo ek operation complete hone tak doosre operation ko rok deta hai. Matlab agar ek function execute ho raha hai, toh jab tak wo complete nahi hota, agla kaam nahi hoga. Agar hum Node.js me fs.readFileSync() ka use karein, toh ye Blocking hoga, kyunki jab tak file read nahi hoti, agla kaam nahi hoga.
Non-Blocking (Asynchronous): Non-blocking code wo hota hai jo ek kaam ke hone ka intezar nahi karta, balki doosre kaam ko execute hone deta hai. Matlab ek function background me chalta rahta hai aur baaki kaam bhi saath-saath chalte hain. Agar hum fs.readFile() ka use karein, toh ye Non-Blocking hoga, kyunki ye kaam background me chalayega aur baki code execute hota rahega.
🟢 1. fs.readFile()
File ko asynchronously read karta hai (Non-Blocking).
🔴 2. fs.readFileSync()
File ko synchronously read karta hai (Blocking).
🟢 3. fs.writeFile()
File me asynchronously data likhta hai (agar file exist nahi karti toh naye file bana deta hai).
🔴 4. fs.writeFileSync()
File me synchronously data likhta hai.
🟢 5. fs.appendFile()
File ke end me data add karta hai bina purana data hataye (Asynchronous).
🔴 6. fs.appendFileSync()
File ke end me data add karta hai, lekin Blocking mode me.
🟢 7. fs.unlink()
File ko delete karta hai (Asynchronous).
🔴 8. fs.unlinkSync()
File ko delete karta hai (Blocking).
🟢 9. fs.rename()
File ka naam change karta hai (Asynchronous).
🔴 10. fs.renameSync()
File ka naam change karta hai (Blocking).
🟢 11. fs.mkdir()
Naya folder (directory) create karta hai (Asynchronous).
🔴 12. fs.mkdirSync()
Folder create karta hai (Blocking).
🟢 13. fs.rmdir()
Folder delete karta hai (Asynchronous).
🔴 14. fs.rmdirSync()
Folder delete karta hai (Blocking).
🟢 15. fs.stat()
File ya folder ki details (size, type, last modified, etc.) deta hai (Asynchronous).
🔴 16. fs.statSync()
File ya folder ki details deta hai (Blocking).
Define: Client ki taraf se request aati hai, jo Event Queue me jati hai. Event Queue First In First Out hoti hai, lekin Node.js me priority-based execution bhi hoti hai. Event Loop continuously check karta hai ke Event Queue me koi request hai ya nahi. Agar request Non-Blocking ho to Event Loop usay direct process kar ke response bhej deta hai. Agar request Blocking ho to Event Loop usay Thread Pool me bhejta hai. Thread Pool me ek thread request ko process karta hai aur phir wapas available ho jata hai. Jab processing complete hoti hai to Event Loop response client ko return kar deta hai. By default, Thread Pool me 4 threads hote hain jo Blocking operations ko handle karte hain.
Thread Pool ek set of worker threads hota hai jo Node.js me Blocking operations ko handle karta hai, taake Event Loop block na ho. By default, isme 4 threads hote hain, lekin UV_THREADPOOL_SIZE variable ke zariye isay increase kiya ja sakta hai. Maximum limit system ke CPU cores par depend karti hai.
Express.js ek lightweight aur flexible web application framework hai jo Node.js ke upar built hai. Yeh server-side applications aur RESTful APIs banane ke liye use hota hai. Express.js Node.js ke HTTP module ko simplify karta hai, taake developers asani se routes handle, middlewares use, aur request-response cycle manage kar sakein.
Node.js directly bhi HTTP server bana sakta hai, lekin Express.js development process ko simplify karta hai aur
repetitive tasks ko automate karta hai.
Agar sirf Node.js ka HTTP module use karein, to request handling, routing, middleware management, aur response
structure sab kuch manually likhna parta hai. Express.js yeh sab cheezein efficiently handle karta hai.
Software versions Semantic Versioning (SemVer) follow karti hain, jo MAJOR.MINOR.PATCH format me hoti hai.
🔹 4 (Major) → Yeh breaking changes show karta hai, jo backward compatibility tod sakti hain.
🔹 21 (Minor) → Yeh new features ya improvements show karta hai, jo backward compatible hote hain.
🔹 2 (Patch) → Yeh small bug fixes ya security updates show karta hai, jo koi major impact nahi dalte.
📝 Example Explanation:
Agar 4.21.2 se 5.0.0 aata hai, to iska matlab hai koi big change ya breaking update aayi hai. Agar 4.22.0 aata
hai, to naye features add huay hain, lekin purane features ab bhi kaam karein ge. Aur agar 4.21.3 aata hai, to
sirf minor bug fixes ya security patches diye gaye hain.
Jab kisi package ka version define kiya jata hai, to ~ aur ^ ka use compatibility control ke liye hota hai. Yeh
dono package.json me dependencies ke version control ko handle karte hain.
1️⃣ ~ (Tilde) → Minor Updates Allow
Sirf Patch Updates Allowed Hain (e.g., 4.21.3, 4.21.4 tak update ho sakta hai)
~4.21.2 → Yeh 4.21.x tak allow karega (patch updates), lekin 4.22.0 ya 5.0.0 install nahi karega.
2️⃣ ^ (Caret) → Minor + Patch Updates Allow
Minor aur Patch Updates Allowed Hain (e.g., 4.22.0, 4.23.0 tak update ho sakta hai)
^4.21.2 → Yeh 4.x.x tak allow karega (minor aur patch updates), lekin 5.0.0 install nahi karega.
✔ ~ (Tilde): Sirf patch updates allow karta hai.
✔ ^ (Caret): Minor aur patch updates allow karta hai.
✔ Dono symbols breaking changes ko prevent karte hain, taake code stable rahe.
SSR (Server-Side Rendering) ek technique hai jisme server pe HTML page generate hota hai aur fully rendered page browser ko bhej diya jata hai. Yeh SEO aur performance improve karne ke liye use hota hai.
JSON (JavaScript Object Notation) ek lightweight aur human-readable data interchange format hai, jo text-based
hota hai. Yeh structured data ko store aur transmit karne ke liye use hota hai. JSON ko JavaScript me easily parse
kiya ja sakta hai, lekin yeh language-independent hai, is liye almost har programming language me use ho sakta
hai.
JSON ka structure key-value pairs me hota hai, jo objects aur arrays ke form me arranged hote hain.
Server-Client Architecture ek software design pattern hai jisme do primary components hote hain: Server aur
Client. Is model mein, server aur client apne respective roles mein work karte hain, jisme server data store
karne, process karne, aur serve karne ka kaam karta hai, jabke client uss data ko request karta hai aur display ya
process karta hai.
1️⃣ Client ek request send karta hai (for example, a browser request for a webpage).
2️⃣ Server us request ko receive karta hai, data process karta hai, aur appropriate response bhejta hai (for
example, HTML, JSON, etc.).
3️⃣ Client response ko receive karta hai aur user ko display karta hai (e.g., rendering a webpage).
REST API (Representational State Transfer API) ek architectural style hai jo web services ke liye use hota hai.
Yeh stateless aur lightweight hota hai, jo data ko client aur server ke beech efficiently exchange karne ke liye
design kiya jata hai.
REST API mein, resources ko URLs ke zariye identify kiya jata hai aur HTTP methods ka use karke un resources pe
operations kiye jate hain.
1️⃣ Stateless – Har request mein server ko client ke baare mein koi information nahi hoti, har request independent
hoti hai.
2️⃣ Client-Server Architecture – Server aur client alag hote hain, aur client sirf request karta hai, jabke server
response deta hai.
3️⃣ Uniform Interface – API ko use karte waqt ek consistent aur standard interface hota hai, jo easy to use hota
hai.
4️⃣ Cacheable – Agar response cacheable ho, to client ko same data ke liye bar-bar request nahi bhejni padti.
5️⃣ Layered System – REST API ko ek layered architecture mein design kiya jata hai, jisme alag-alag layers handle
karte hain, jaise authentication, load balancing, etc.
6️⃣ Use of HTTP Methods – REST APIs mein GET, POST, PUT, DELETE jaise HTTP methods ka use hota hai.
Middleware Express.js aur backend development ka ek important concept hai. Yeh ek function hota hai jo request aur response ke beech execute hota hai. Middleware ka kaam request ko modify karna, authentication check karna, logging karna, error handling aur doosre important tasks ko handle karna hota hai.0
HTTP headers additional metadata hoti hain jo request aur response ke sath send ki jati hain. Yeh client aur
server ke darmiyan communication ko control karne aur secure banane ke liye istemal hoti hain.
Jab bhi client (browser ya API client) server se request bhejta hai, to us request ke sath kuch headers hotay
hain. Server bhi response bhejte waqt headers attach karta hai.
HTTP status codes server ke responses hain jo batate hain ke request ka kya result aaya hai. Ye 5 categories main
divide hote hain:
✅ 1XX – Informational (Processing Chal Rahi Hai)
100 Continue → Request sahi hai, continue karo.
101 Switching Protocols → Server protocol change kar raha hai.
✅ 2XX – Success (Request Sahi Hui)
200 OK → Request successful, data mil gaya.
201 Created → Naya data successfully create ho gaya.
204 No Content → Request successful, but koi content nahi hai.
⛔ 3XX – Redirection (Dusri Jagah Redirect Karna)
301 Moved Permanently → Resource hamesha ke liye dusri jagah move ho gaya.
302 Found → Resource temporarily move hua hai.
304 Not Modified → Data change nahi hua, cache use karo.
⚠️ 4XX – Client Errors (Request Galat Hai)
400 Bad Request → Request format galat hai.
401 Unauthorized → Authentication required hai (login karo).
403 Forbidden → Permission nahi hai.
404 Not Found → Resource nahi mila.
🚨 5XX – Server Errors (Server Ki Ghalti)
500 Internal Server Error → Server pe koi unknown error hai.
502 Bad Gateway → Server se response nahi mila.
503 Service Unavailable → Server busy ya down hai.
MongoDB ek NoSQL database hai jo JSON-like documents me data store karta hai. Yeh flexible, fast, aur scalable hai, aur structured (SQL) databases ki tarah tables use nahi karta. Instead, yeh collections aur documents ka use karta hai.
Mongoose ek Object Data Modeling (ODM) library hai jo MongoDB ke saath kaam karne ke liye use hoti hai. Yeh MongoDB ke documents ko structured tareeke se handle karne ke liye ek schema-based approach provide karti hai. Mongoose asynchronous queries ko support karta hai aur validation, middleware, aur built-in query functions ka use karke MongoDB operations ko simplify karta hai.
Schema ek blueprint hai jo MongoDB ke documents ka structure define karta hai. Yeh batata hai ke ek collection ke andar ka data kis format aur type ka hoga. Schema me hum fields ka data type, validation rules, aur default values define kar sakte hain. Yeh ensure karta hai ke database me jo data store ho, wo ek specific format ko follow kare.
Model ek constructor function hai jo schema ka use karke MongoDB collections se interact karta hai. Yeh ek instance hota hai jo database ke documents par CRUD (Create, Read, Update, Delete) operations perform karta hai. Model ke through hum MongoDB se data insert, retrieve, update, aur delete kar sakte hain.
MVC ek design pattern hai jo applications ko structured aur maintainable banane ke liye use hota hai. Is pattern
me application ko 3 main parts me divide kiya jata hai:
Model (M) – Data aur database logic handle karta hai.
View (V) – User Interface (UI) ko manage karta hai.
Controller (C) – User requests ko handle karta hai aur Model aur View ke beech coordination karta hai.
Stateless ka matlab hai ke server kisi bhi user ka session ya data apne paas store nahi karta.
Jab bhi koi user request bhejta hai, uske sath JWT token hota hai. Server har request ko alag se verify karta hai,
lekin koi previous request ka record nahi rakhta.
Example:
Session-Based (Stateful)
User login karta hai → Server session store karta hai.
Har request par server database check karta hai ke user kaun hai.
JWT-Based (Stateless)
User login karta hai → Server JWT generate karta hai aur client ko de deta hai.
Har request me client JWT bhejta hai, aur server bas usko verify karta hai, koi extra session store nahi hota.
Stateless hone ke faide:
✅ Fast & Scalable – Har request independent hoti hai.
✅ Load Balancing Easy – Multiple servers ke sath kaam kar sakta hai.
✅ Less Server Load – Server ko user sessions store nahi karne padte.
Asaan lafzon me, stateless ka matlab hai ke server sirf token verify karega, lekin user ka data ya session apne
paas nahi rakhega.
JWT (JSON Web Token) ek special string hoti hai jo authentication aur secure data transfer ke liye use hoti hai.
Yeh ek unique pass ki tarah kaam karti hai jo user ki identity confirm karne aur unauthorized access rokne ke liye
server aur client ke beech exchange hoti hai.
Is token mein user ka basic data hota hai (jaise id, email, role), jo encrypt aur sign kiya jata hai, taki koi
usko modify na kar sake. JWT stateless hoti hai, yani server ko session maintain karne ki zaroorat nahi hoti, sirf
token verify karni hoti hai.
Asaan lafzon mein:
✅ JWT ek identity proof hai jo har request ke sath jata hai.
✅ Login hone ke baad server ek JWT generate karta hai aur client ko bhejta hai.
✅ Client har request ke sath JWT bhejta hai taki server user ko pehchan sake.
✅ JWT secure aur scalable authentication system hai.
Cookies ek small text file hoti hain jo browser me store hoti hai aur website ke liye user ki information ya settings ko yaad rakhti hai. Ye authentication, user preferences, session management aur tracking ke liye use hoti hain.
Authentication:
👉 Authentication ka matlab hai verify karna ki user kaun hai.
🔹 Jab koi user login karta hai, to system check karta hai ki ye "real user hai ya nahi".
🔹 Iske liye username & password, OTP, biometric scan ya social login (Google, Facebook) ka use hota hai.
🔹 Example:
Tum kisi office building ke main gate pe jaate ho aur security guard tumse ID Card maangta hai.
✔ Agar tumhara ID Card valid hai, to guard confirm karega ki tum authorized employee ho aur tumhe andar jane
dega.
✔ Agar ID Card invalid hai, to tumhe entry nahi milegi.
🛑 Authentication bina authorization possible nahi hai. Pehle system verify karega ki tum kaun ho, phir decide
karega ki tumhe kya access milna chahiye.
Authorization:
👉 Authorization ka matlab hai decide karna ki ek authenticated user kis cheez ko access kar sakta hai.
🔹 Jab ek user authenticate ho jata hai, to system decide karta hai ki usko kin resources ya features ka access
milna chahiye.
🔹 Example:
Office building me enter hone ke baad tum har jagah nahi ja sakte.
✔ Agar tum normal employee ho, to tum sirf work area me ja sakte ho.
✔ Agar tum manager ho, to tum conference room ya server room ka access le sakte ho.
✔ Agar tum CEO ho, to tum pure office ke sabhi areas me ja sakte ho.
🛑 Authorization bina authentication ke nahi ho sakta. Pehle system confirm karega ki tum ho kaun, phir tumhe
🛑 Authorization bina authentication ke nahi ho sakta. Pehle system confirm karega ki tum ho kaun, phir tumhe
access milega.
HTTP Headers additional metadata hoti hai jo client aur server ke beech request-response me exchange hoti hai. Ye
security, content type, caching, aur authentication jaise aspects control karti hai.
Authorization header ek special header hota hai jo protected APIs ko access karne ke liye use hota hai. Bearer
Token ek authentication token hai jo JWT ya kisi aur authentication system ka hissa hota hai. Server is token ko
verify karta hai aur agar valid ho to access deta hai.
Types of Headers:
1️⃣ Request Headers: Client (browser or app) se server ko bheje jate hain.
Example: Authorization, Content-Type, User-Agent
2️⃣ Response Headers: Server se client ko bheje jate hain.
Example: Set-Cookie, Cache-Control, Content-Length
Multer ek middleware hai jo Express.js me file uploads handle karne ke liye use hota hai. Ye multipart/form-data requests ko process karta hai aur uploaded files ko server me disk ya memory me save karne ka option deta hai. Iska use image uploads, profile pictures, document uploads aur cloud storage integrations ke liye hota hai.
Socket.io ek real-time, event-driven communication library hai jo client aur server ke beech WebSockets ya long polling ka use karke instant data exchange allow karti hai. Ye live chat, notifications, gaming, real-time collaboration jaise applications me use hoti hai. Iska architecture bidirectional aur event-based hota hai jisme server aur client dono data send aur receive kar sakte hain.
A pipeline ek process hai jo multiple steps me data ya processes ko pass karne ke liye use hota hai. Iska use software development (CI/CD), data processing (ETL), database operations (MongoDB Aggregation), aur command-line processing me hota hai. Har step previous step ka output as input leta hai aur efficient execution ensure karta hai.
A stream ek continuous data flow ko efficiently process karne ka tareeqa hai jisme large data ko small chunks me process kiya jata hai, taake memory overload na ho aur performance optimize rahe.
Gzip ek compression algorithm hai jo data ko smaller size me convert karta hai. Node.js me zlib.createGzip() aur zlib.createGunzip() ka use hota hai file compression aur decompression ke liye.
Cluster module Node.js applications ko multiple processes me distribute karne ke liye use hota hai, taake multi-core CPUs ka full utilization ho sake aur performance improve ho. Yeh ek Master-Worker architecture follow karta hai jisme master process multiple worker processes spawn karta hai jo requests handle karte hain.
Node.js single-threaded hota hai, jo high traffic applications ke liye bottleneck create kar sakta hai. Cluster module multiple processes run karke concurrent request handling improve karta hai, jisse application ka throughput aur efficiency badh jati hai.
NGINX ek high-performance web server hai jo reverse proxy, load balancing, caching aur static
content serve karne ke liye use hota hai. Ye zyada concurrent requests handle karne ke liye design kiya gaya hai.
NGINX Ke Key Features:
Reverse Proxy – Client (user) ki request ko backend servers tak pohchata hai.
Load Balancer – Traffic ko multiple servers par distribute karta hai taake performance better ho.
HTTP Caching – Frequently accessed responses ko cache karta hai jisse speed improve hoti hai.
API Gateway – API requests ko manage aur secure karta hai.
SSL Certificates Handle Karna – HTTPS aur security ke liye SSL/TLS manage karta hai.
Static File Handling – Images, videos, aur static content ko efficiently serve aur cache karta hai.
NGINX Kyun Use Kiya Jata Hai?
10,000+ concurrent connections ko smoothly handle kar sakta hai.
Websites aur applications ki speed aur reliability improve karta hai.
Security enhance karta hai, DDoS attacks ko mitigate karne me madad deta hai.
schema.pre() Mongoose ka ek middleware hook hai jo kisi operation (like save, update, remove, etc.) ke hone se
pehle execute hota hai. Ye data validate, modifications, ya business logic apply karne ke liye useful hota hai.
"Jab bhi koi document database me save hone wala ho, ye middleware pehle execute hoga."