Scene: Tech Cafe, where server concepts gather for a light-hearted yet insightful debate.
Characters:
HTTP Server
- The Starterhttp Module
- The FoundationGET Request Handler
- The RetrieverPOST Request Handler
- The Data Acceptorurl Module
- The NavigatorHTTPS
- The Security GuardRouter
- The GuideMiddleware
- The Traffic ControllerFile Uploader
- The Transporternet Module
- The Low-level Worker
Narrator: Tech Café mein aaj networking aur server concepts ek dusre ko apni taqat, capabilities, aur zaroorat ke baare mein batate hue thoda masti aur comedy kar rahe hain.
HTTP Server:
HTTP Server (Confidently): "Main toh basic kaam karta hoon Node.js mein, simple HTTP server create karna. Dekho:
javascript
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, world!');
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Main sabko connect kar deta hoon aur server start karta hoon. Simple kaam, par bina mere sab zero!"
http Module:
http Module (Seriously): "Arrey! Sabko yeh samajhna chahiye ki main basic building block hoon Node.js servers ka. Mere bina HTTP server banega kaise?
javascriptconst http = require('http');
// Yeh module ko import kiya, aur phir server bana.
Main hi sabko handle karta hoon - incoming requests aur outgoing responses. Sab kuch mujh par dependent hai!"
GET Request Handler:
GET Request Handler (With a wink): "Arey, main hi toh data fetch karne mein expert hoon! Jab kisi ko information chahiye hoti hai, toh GET request aata hai. Yeh dekho, kaise handle karta hoon main:
javascript
const http = require('http');
const server = http.createServer((req, res) => {
if (req.method === 'GET') {
res.statusCode = 200;
res.end('You made a GET request!');
}
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Main efficient aur fast hoon, bas mujhe data chahiye, aur main le aata hoon!"
POST Request Handler:
POST Request Handler (Smugly): "Haan, GET bhai, tum data laate ho, lekin main data ko accept karta hoon, aur store bhi karta hoon. Dekho:
javascript
const http = require('http');
const server = http.createServer((req, res) => {
if (req.method === 'POST') {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
res.end(`Received data: ${body}`);
});
}
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Mere bina data create aur update kaise hoga? Main hoon jo asli kaam karta hoon!"
url Module:
url Module (Politely): "Main sabko sahi raasta dikhata hoon, yani URL ko parse aur analyze karta hoon. Mere bina tum URL ko samajh nahi paoge:
javascript
const url = require('url');
const myURL = url.parse('http://example.com/pathname?name=abc&age=23', true);
console.log(myURL.pathname); // Output: '/pathname'
console.log(myURL.query); // Output: { name: 'abc', age: '23' }
Main URLs ko decode karta hoon aur tumhe bataata hoon ki query parameters kya hain."
HTTPS:
HTTPS (With pride): "Bhai, main hoon jo security provide karta hoon. HTTP bhai ki tarah kaam karta hoon, bas thoda zyada secure:
javascript
const https = require('https');
// Aage certificate aur key add karo, aur server ko secure banao.
Mere bina tumhare sensitive data ka kya hoga? Mujhe apna role sabko samjha dena chahiye."
Router:
Router (Casually): "Mujhe kaha jaata hai bina framework ke routing implement karna impossible hai! Main tumhe dikhaata hoon:
javascript
const http = require('http');
const server = http.createServer((req, res) => {
if (req.url === '/home') {
res.end('Welcome to Home Page');
} else if (req.url === '/about') {
res.end('About Us Page');
} else {
res.end('404 Page Not Found');
}
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Mere bina users ko sahi jagah kaise milta? Main guide hoon sabka!"
Middleware:
Middleware (Smartly): "Arey main toh request aur response ke beech ka hero hoon. Sab requests mere se hote hue pass karte hain:
javascript
const http = require('http');
const middleware = (req, res, next) => {
console.log(`Request URL: ${req.url}`);
next();
};
const server = http.createServer((req, res) => {
middleware(req, res, () => {
res.end('Hello Middleware!');
});
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Main toh control deta hoon ki request ka flow kaise hoga, aur additional functionality bhi add karta hoon!"
File Uploader:
File Uploader (Energetically): "Mera kaam toh bada interesting hai! Main files upload karne mein expert hoon:
javascript
const http = require('http');
const fs = require('fs');
const server = http.createServer((req, res) => {
if (req.method === 'POST' && req.url === '/upload') {
let fileStream = fs.createWriteStream('uploaded_file');
req.pipe(fileStream);
req.on('end', () => {
res.end('File uploaded!');
});
}
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Main toh files ko server par securely store kar deta hoon. Mere bina file handling kaise hoti?"
net Module:
net Module (Gravely): "Main hoon low-level networking ka master. HTTP aur HTTPS mujhe istemal karte hain apne protocols ke liye. Main basic socket programming handle karta hoon:
javascript
const net = require('net');
const server = net.createServer((socket) => {
socket.write('Hello from TCP server!\n');
socket.end();
});
server.listen(3000, () => {
console.log('TCP server running at port 3000');
});
Main toh bina protocol ke bhi communication establish kar leta hoon. Main hardcore networking ka king hoon!"
Narrator: Coding aur networking ki yeh café baatcheet bataati hai ki kaise har ek module aur concept ka apna importance hai. Har ek apna role play karta hai, aur bina ek dusre ke, koi bhi server pura nahi ho sakta.
0 Comments