<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vivek Rastogi on Medium]]></title>
        <description><![CDATA[Stories by Vivek Rastogi on Medium]]></description>
        <link>https://medium.com/@rastogi.programmer?source=rss-a508adfb19bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*y0Bj0se6QMUmPWRLuqxxPA.jpeg</url>
            <title>Stories by Vivek Rastogi on Medium</title>
            <link>https://medium.com/@rastogi.programmer?source=rss-a508adfb19bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 02:28:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rastogi.programmer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[What is Middleware in Express?]]></title>
            <link>https://medium.com/@rastogi.programmer/what-is-middleware-in-express-b466a55c7eb2?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/b466a55c7eb2</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Wed, 13 Aug 2025 12:24:57 GMT</pubDate>
            <atom:updated>2025-08-13T12:24:57.963Z</atom:updated>
            <content:encoded><![CDATA[<p>Middleware is a <strong>function that runs during the request-response cycle</strong>.</p><h3>Think of middleware as:</h3><p><em>A </em><strong><em>custom security checkpoint</em></strong><em> between the request and the final route handler.</em></p><h3>Where Does Middleware Fit?</h3><p>When someone sends a request to your server:</p><pre>Client Request → Middleware 1 → Middleware 2 → Route Handler → Response</pre><p>Middleware can:</p><ul><li>Log data</li><li>Authenticate users</li><li>Modify request/response</li><li>Handle errors</li><li>Stop or pass to the next step using next()</li></ul><h3>Syntax of Middleware</h3><pre>function middlewareName(req, res, next) {<br>  // Do something<br>  next(); // Move to next middleware/route<br>}</pre><h3>Example 1: Logging Middleware (Global)</h3><pre>const express = require(&#39;express&#39;);<br>const app = express();<br><br>// Middleware<br>app.use((req, res, next) =&gt; {<br>  console.log(`${req.method} ${req.url}`);<br>  next(); // Important to move to the next handler<br>});<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello, Mahadev!&#39;);<br>});<br>app.listen(3000, () =&gt; console.log(&#39;Server running&#39;));</pre><p>Output on visiting /:</p><pre>GET /</pre><h3>Example 2: Middleware for a Specific Route</h3><pre>function checkAdmin(req, res, next) {<br>  const isAdmin = false;<br>  if (isAdmin) {<br>    next();<br>  } else {<br>    res.status(403).send(&#39;Access Denied&#39;);<br>  }<br>}<br><br>app.get(&#39;/admin&#39;, checkAdmin, (req, res) =&gt; {<br>  res.send(&#39;Welcome Admin&#39;);<br>});</pre><h3>Example 3: Built-in Middleware</h3><pre>app.use(express.json()); // Parse JSON from request body</pre><h3>Example 4: Error-Handling Middleware</h3><pre>app.use((err, req, res, next) =&gt; {<br>  console.error(err.stack);<br>  res.status(500).send(&#39;Something broke!&#39;);<br>});</pre><p>To trigger:</p><pre>app.get(&#39;/error&#39;, (req, res) =&gt; {<br>  throw new Error(&#39;Force crash&#39;);<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0GciqU-1rsAxeu3XxvpXMA.png" /></figure><h3>Coach’s Advice:</h3><ul><li>Use <strong>app.use()</strong> for global middleware.</li><li>Don’t forget next() or your request may hang.</li><li>Chain multiple middlewares for clarity and separation of logic.</li><li>Learn to use third-party middleware like:</li><li>morgan for logging</li><li>cors for cross-origin requests</li><li>helmet for security</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b466a55c7eb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CRUD API with routes on Express JS]]></title>
            <link>https://medium.com/@rastogi.programmer/crud-api-with-routes-on-express-js-c4ea62c880ca?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4ea62c880ca</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Wed, 13 Aug 2025 12:23:47 GMT</pubDate>
            <atom:updated>2025-08-13T12:23:47.293Z</atom:updated>
            <content:encoded><![CDATA[<p>Great choice, BB! Let’s build a <strong>sample CRUD API using Express.js</strong> with complete <strong>routes</strong> for managing a list of users. This is perfect practice for understanding routing, middleware, and basic REST structure.</p><h3>Tech Stack</h3><ul><li><strong>Node.js + Express.js</strong></li><li>In-memory array for simplicity (no DB)</li><li>JSON responses for all routes</li></ul><h3>Project Structure</h3><pre>crud-api/<br>├── app.js<br>└── routes/<br>    └── users.js</pre><p>Step-by-Step Code</p><h3>📄 app.js – Entry Point</h3><pre>const express = require(&#39;express&#39;);<br>const app = express();<br>const usersRoute = require(&#39;./routes/users&#39;);<br><br>// Middleware to parse JSON<br>app.use(express.json());<br>// Route Middleware<br>app.use(&#39;/api/users&#39;, usersRoute);<br>// Start Server<br>const PORT = 3000;<br>app.listen(PORT, () =&gt; {<br>  console.log(`Server is running on http://localhost:${PORT}`);<br>});</pre><h3>📄 routes/users.js – User Routes</h3><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();<br><br>// Mock data (in-memory)<br>let users = [<br>  { id: 1, name: &#39;Shiva&#39; },<br>  { id: 2, name: &#39;Parvati&#39; },<br>];<br><br>// GET all users<br>router.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.json(users);<br>});<br><br>// GET single user by ID<br>router.get(&#39;/:id&#39;, (req, res) =&gt; {<br>  const user = users.find(u =&gt; u.id == req.params.id);<br>  if (!user) return res.status(404).send(&#39;User not found&#39;);<br>  res.json(user);<br>});<br><br>// POST create a new user<br>router.post(&#39;/&#39;, (req, res) =&gt; {<br>  const newUser = {<br>    id: users.length + 1,<br>    name: req.body.name<br>  };<br>  users.push(newUser);<br>  res.status(201).json(newUser);<br>});<br><br>// PUT update user<br>router.put(&#39;/:id&#39;, (req, res) =&gt; {<br>  const user = users.find(u =&gt; u.id == req.params.id);<br>  if (!user) return res.status(404).send(&#39;User not found&#39;);<br>  user.name = req.body.name;<br>  res.json(user);<br>});<br><br>// DELETE a user<br>router.delete(&#39;/:id&#39;, (req, res) =&gt; {<br>  const userIndex = users.findIndex(u =&gt; u.id == req.params.id);<br>  if (userIndex === -1) return res.status(404).send(&#39;User not found&#39;);<br>  const deletedUser = users.splice(userIndex, 1);<br>  res.json(deletedUser[0]);<br>});<br>module.exports = router;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qmivp4uvUR3kL0Tfh0NFiA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4ea62c880ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Request & Response Sending text, HTML, JSON responses in Express JS]]></title>
            <link>https://medium.com/@rastogi.programmer/request-response-sending-text-html-json-responses-in-express-js-323026c9faaf?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/323026c9faaf</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Wed, 13 Aug 2025 12:21:24 GMT</pubDate>
            <atom:updated>2025-08-13T12:21:24.209Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s talk about how to <strong>work with request and response objects</strong> (req and res) in Express.js — this is your <strong>main communication channel</strong> between the <strong>client and server</strong>.</p><h3>What are req and res?</h3><p>In every route handler, Express provides you with:</p><pre>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  // req: request from the client<br>  // res: response from the server<br>});</pre><h3>1. Sending Plain Text</h3><pre>app.get(&#39;/text&#39;, (req, res) =&gt; {<br>  res.send(&#39;Namaste from Mahadev’s server!&#39;);<br>});</pre><p>🧠 <em>Perfect for simple checks or greetings.</em></p><h3>2. Sending HTML Content</h3><pre>app.get(&#39;/html&#39;, (req, res) =&gt; {<br>  res.send(`<br>    &lt;h1&gt;Welcome to Kailash&lt;/h1&gt;<br>    &lt;p&gt;Mahadev is meditating...&lt;/p&gt;<br>  `);<br>});</pre><p>🧠 <em>Use when you want to return a full HTML snippet directly.</em></p><h3>3. Sending JSON (for APIs)</h3><pre>app.get(&#39;/json&#39;, (req, res) =&gt; {<br>  res.json({<br>    name: &#39;Mahadev&#39;,<br>    trishul: true,<br>    followers: [&#39;Nandi&#39;, &#39;Ganesha&#39;, &#39;Parvati&#39;]<br>  });<br>});</pre><p>🧠 <em>This is best when you’re building APIs for frontend apps (React, Angular, etc.).</em></p><h3>4. Using res.status() to Set HTTP Status</h3><pre>app.get(&#39;/notfound&#39;, (req, res) =&gt; {<br>  res.status(404).send(&#39;This page</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cj6O5wds_goabK9hwWh8WA.png" /></figure><h3>5. Request Parameters (req.params &amp; req.query)</h3><pre>app.get(&#39;/user/:name&#39;, (req, res) =&gt; {<br>  res.send(`Namaste, ${req.params.name}`);<br>});</pre><pre>// Example URL: /user/shiva → Response: Namaste, shiva</pre><pre>app.get(&#39;/search&#39;, (req, res) =&gt; {<br>  res.send(`You searched for: ${req.query.q}`);<br>});<br><br>// Example URL: /search?q=parvati → Response: You searched for: parvati</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=323026c9faaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is express.urlencoded()?]]></title>
            <link>https://medium.com/@rastogi.programmer/what-is-express-urlencoded-6f710860e09f?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f710860e09f</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 15:05:29 GMT</pubDate>
            <atom:updated>2025-07-29T15:05:29.913Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is express.urlencoded()?</h3><p>express.urlencoded() is a <strong>built-in middleware</strong> in Express that helps your server <strong>read form data</strong> sent via:</p><ul><li>application/x-www-form-urlencoded (the default form type in HTML)</li></ul><h3>Why Do You Need It?</h3><p>When you submit an HTML form using POST, the data is sent to the server in a <strong>URL-encoded format</strong> like:</p><pre>name=Shiva&amp;power=Trishul</pre><p>Without express.urlencoded(), your Express app <strong>won’t understand</strong> this data.</p><h3>Syntax</h3><pre>app.use(express.urlencoded({ extended: true }));</pre><blockquote><em>extended: true allows for nested objects (more flexible parsing)</em></blockquote><h3>Step-by-Step Example</h3><h3>🧱 1. Create a simple HTML form</h3><p><strong>form.html</strong></p><pre>&lt;form action=&quot;/submit&quot; method=&quot;POST&quot;&gt;<br>  &lt;label&gt;Name:&lt;/label&gt;<br>  &lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt;<br>  &lt;br/&gt;<br>  &lt;label&gt;Power:&lt;/label&gt;<br>  &lt;input type=&quot;text&quot; name=&quot;power&quot; /&gt;<br>  &lt;br/&gt;<br>  &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>&lt;/form&gt;</pre><h3>2. Handle it in Express</h3><p><strong>app.js</strong></p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br><br>// Middleware to parse URL-encoded form data<br>app.use(express.urlencoded({ extended: true }));<br>// Route to show the form<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.sendFile(__dirname + &#39;/form.html&#39;);<br>});<br>// Route to handle form submission<br>app.post(&#39;/submit&#39;, (req, res) =&gt; {<br>  const { name, power } = req.body;<br>  res.send(`🧘‍♂️ Welcome, ${name}! Your power is ${power}.`);<br>});<br>app.listen(3000, () =&gt; {<br>  console.log(&#39;Server running at http://localhost:3000&#39;);<br>});</pre><h3>What Happens Here?</h3><ol><li>You open <a href="http://localhost:3000">http://localhost:3000</a></li><li>Fill out the form (e.g., name = Shiva, power = Trishul)</li><li>Hit submit → it sends a POST request to /submit</li><li>Express uses express.urlencoded() to <strong>parse </strong><strong>req.body</strong></li><li>You send back a response using that data</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gz13vb8enMURCKcbAx4dw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f710860e09f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is multer?]]></title>
            <link>https://medium.com/@rastogi.programmer/what-is-multer-22ecfd6ecafe?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/22ecfd6ecafe</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 14:53:58 GMT</pubDate>
            <atom:updated>2025-07-29T14:53:58.909Z</atom:updated>
            <content:encoded><![CDATA[<p>multer is a <strong>middleware</strong> for handling multipart/form-data, which is used <strong>specifically for uploading files</strong> like:</p><ul><li>Profile pictures</li><li>PDFs, documents</li><li>Image galleries</li><li>Product photos</li></ul><p>Install Multer</p><pre>npm install multer</pre><h3>🗂️ Project Structure</h3><pre>file-upload-app/<br>├── uploads/            # &lt;- where files will be saved<br>├── app.js<br>└── form.html</pre><h3>Step-by-Step Code</h3><h3>📄 1. HTML Form</h3><p><strong>form.html</strong></p><pre>&lt;form action=&quot;/upload&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;<br>  &lt;input type=&quot;file&quot; name=&quot;myfile&quot; /&gt;<br>  &lt;button type=&quot;submit&quot;&gt;Upload&lt;/button&gt;<br>&lt;/form&gt;</pre><p>enctype=&quot;multipart/form-data&quot; is <strong>required</strong> for file uploads.</p><h3>2. Express App with Multer</h3><p><strong>app.js</strong></p><pre>const express = require(&#39;express&#39;);<br>const multer = require(&#39;multer&#39;);<br>const path = require(&#39;path&#39;);<br>const app = express();<br><br>// Set storage engine<br>const storage = multer.diskStorage({<br>  destination: &#39;./uploads/&#39;,<br>  filename: (req, file, cb) =&gt; {<br>    cb(null, Date.now() + &#39;-&#39; + file.originalname);<br>  }<br>});<br>// Initialize upload middleware<br>const upload = multer({ storage: storage });<br>// Serve form page<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.sendFile(__dirname + &#39;/form.html&#39;);<br>});<br>// Handle file upload<br>app.post(&#39;/upload&#39;, upload.single(&#39;myfile&#39;), (req, res) =&gt; {<br>  if (!req.file) {<br>    return res.send(&#39;No file uploaded.&#39;);<br>  }<br>  res.send(`File uploaded: ${req.file.filename}`);<br>});<br>// Start server<br>app.listen(3000, () =&gt; {<br>  console.log(&#39;Server running at http://localhost:3000&#39;);<br>});</pre><h3>📂 Uploaded File Access</h3><p>Once uploaded, files are saved in the uploads/ directory, e.g.:</p><pre>uploads/1721667643010-shiva.jpg</pre><p>You can make this folder publicly accessible with:</p><pre>app.use(&#39;/uploads&#39;, express.static(&#39;uploads&#39;));</pre><p>Then access files like:<br> 📎 <a href="http://localhost:3000/uploads/filename.jpg">http://localhost:3000/uploads/filename.jpg</a></p><h3>Security Tips from Coach</h3><p>✅ Always validate file types:</p><pre>const fileFilter = (req, file, cb) =&gt; {<br>  const types = /jpeg|jpg|png|pdf/;<br>  const ext = types.test(path.extname(file.originalname).toLowerCase());<br>  if (ext) return cb(null, true);<br>  cb(&#39;Only images or PDFs allowed!&#39;);<br>};</pre><pre>const upload = multer({ storage, fileFilter });</pre><p>✅ Limit file size:</p><pre>const upload = multer({ storage, limits: { fileSize: 2 * 1024 * 1024 } }); // 2MB</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zY5vusjkS_MPA-bNM9HaCA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22ecfd6ecafe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Render dynamic HTML pages in Express JS]]></title>
            <link>https://medium.com/@rastogi.programmer/render-dynamic-html-pages-in-express-js-852510e6eaa6?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/852510e6eaa6</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 14:37:19 GMT</pubDate>
            <atom:updated>2025-07-29T14:37:19.172Z</atom:updated>
            <content:encoded><![CDATA[<p>Instead of hardcoding HTML like:</p><pre>res.send(&#39;&lt;h1&gt;Hello BB&lt;/h1&gt;&#39;);</pre><p>You render a <strong>template</strong> and <strong>inject dynamic data</strong>:</p><pre>res.render(&#39;home&#39;, { name: &#39;BB&#39; });</pre><h3>What is a Templating Engine?</h3><p>Templating engines like <strong>EJS, Handlebars, or Pug</strong> allow you to write HTML with placeholders for data.</p><p>We’ll use <strong>EJS (Embedded JavaScript)</strong> — simple and powerful.</p><h3>Step-by-Step: Dynamic HTML with EJS</h3><h3>1. Install EJS</h3><pre>npm install ejs</pre><h3>2. Project Structure</h3><pre>dynamic-html/<br>├── views/<br>│   └── home.ejs<br>├── app.js</pre><h3>3. Setup Express with EJS</h3><p><strong>app.js</strong></p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br><br>// Set EJS as templating engine<br>app.set(&#39;view engine&#39;, &#39;ejs&#39;);<br>// Render home.ejs<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.render(&#39;home&#39;, { name: &#39;Mahadev&#39;, power: &#39;Trishul&#39; });<br>});<br>app.listen(3000, () =&gt; {<br>  console.log(&#39;Server running at http://localhost:3000&#39;);<br>});</pre><h3>4. Create EJS Template</h3><p><strong>views/home.ejs</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;Welcome Page&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h1&gt;Namaste &lt;%= name %&gt;!&lt;/h1&gt;<br>  &lt;p&gt;Your power is: &lt;%= power %&gt;&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>5. Run and Visit</h3><p>Start your server and visit:<br> 👉 <a href="http://localhost:3000">http://localhost:3000</a></p><p>You’ll see:</p><pre>Namaste Mahadev!<br>Your power is: Trishul</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8YGRu_zniyfyjLQNOYV2A.png" /></figure><h3><strong>Use EJS for:</strong></h3><ul><li>Login forms</li><li>Dynamic blog pages</li><li>Admin dashboards</li><li>SEO-friendly pages</li></ul><p>Combine with Express routes to:</p><ul><li>Pass data from DB to HTML</li><li>Show different content per user/page</li></ul><p>Use a views/partials folder for:</p><ul><li>header.ejs, footer.ejs reuse</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=852510e6eaa6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step: Express Hello World]]></title>
            <link>https://medium.com/@rastogi.programmer/step-by-step-express-hello-world-2e9582d58e18?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e9582d58e18</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Wed, 23 Jul 2025 05:26:21 GMT</pubDate>
            <atom:updated>2025-07-23T05:26:21.570Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create a Project Folder</h4><pre>mkdir my-express-app<br>cd my-express-app</pre><h4>2. Initialize the Project</h4><pre>npm init -y</pre><p>This creates a package.json file.</p><h4>3. Install Express</h4><pre>npm install express</pre><h4>Create app.js (Your Main File)</h4><pre>// app.js<br>const express = require(&#39;express&#39;);<br>const app = express();<br>// Define a route<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello, Mahadev!&#39;);<br>});<br>// Start the server<br>const PORT = 3000;<br>app.listen(PORT, () =&gt; {<br>  console.log(`Server running at http://localhost:${PORT}`);<br>});</pre><h4>Run the Server</h4><pre>node app.js</pre><h3>What You Just Did:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*kUtPK9vO_FflGMuMq436zQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9582d58e18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js vs Express.js]]></title>
            <link>https://medium.com/@rastogi.programmer/node-js-vs-express-js-40d8c1877b74?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/40d8c1877b74</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Tue, 22 Jul 2025 13:57:54 GMT</pubDate>
            <atom:updated>2025-07-22T13:57:54.661Z</atom:updated>
            <content:encoded><![CDATA[<h3>🛠️ Node.js: The Engine</h3><p>Node.js is a <strong>runtime environment</strong> that lets you run JavaScript on the server.</p><ul><li>It uses Google Chrome’s V8 engine.</li><li>It’s <strong>event-driven</strong> and <strong>non-blocking</strong>, which makes it great for handling many connections at once (like chat apps, APIs, etc.).</li><li>But by itself, it’s <strong>low-level</strong> — you have to write a lot of boilerplate code even for simple tasks like routing or sending HTML.</li></ul><p><strong>Think of Node.js as the raw power</strong> — like an engine block in a car.</p><h3>Express.js: The Toolkit on Top of Node.js</h3><p>Express.js is a <strong>framework built on top of Node.js</strong> to make your life easier.</p><ul><li>It simplifies <strong>routing</strong>, <strong>middleware</strong>, <strong>error handling</strong>, <strong>request/response management</strong>, and more.</li><li>You can create a full API or website in 5–10 lines of code.</li><li>It adds structure and gives you useful functions like app.get(), app.post(), res.send(), etc.</li></ul><p><strong>Think of Express.js as the vehicle body, controls, and dashboard</strong> — making Node.js easy to drive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2SCZ4mkeCbQSpGBSlN7Kg.png" /></figure><p>if you’re building <strong>any web-based backend or API</strong>, <strong>don’t use raw Node.js alone</strong> unless you’re doing something extremely custom. Use <strong>Express.js</strong> and focus on your app’s logic — not boilerplate code.</p><h3>Real-World Analogy:</h3><ul><li><strong>Node.js</strong> = You build a house starting with bricks and cement.</li><li><strong>Express.js</strong> = You get pre-cut wood, a drill, and IKEA instructions — it’s all faster, safer, and modular.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40d8c1877b74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ What is Express.js?]]></title>
            <link>https://medium.com/@rastogi.programmer/what-is-express-js-09e1a51d8ad2?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/09e1a51d8ad2</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Tue, 22 Jul 2025 12:25:24 GMT</pubDate>
            <atom:updated>2025-07-22T12:25:24.594Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Express.js</strong> is a <strong>minimal and flexible Node.js web application framework</strong> that helps you build <strong>web servers and APIs quickly and efficiently</strong>.</p><h3>Why Use Express.js?</h3><p>Think of <strong>Node.js</strong> as the engine, and <strong>Express.js</strong> as the <strong>chassis + dashboard</strong> — it provides structure, shortcuts, and tools to build apps faster.</p><p>Without Express, writing a web server in plain Node.js involves a lot of manual code like http.createServer(). Express simplifies this.</p><h3>Key Features of Express.js:</h3><p>===============================================================</p><p><strong>Routing: </strong>Handles different URLs and HTTP methods easily</p><p><strong>Middleware: </strong>Processes requests (e.g., parse JSON, log data, handle errors)</p><p><strong>Templating: </strong>Supports rendering dynamic HTML pages (e.g., using EJS, Handlebars)</p><p><strong>REST APIs: </strong>Makes building RESTful services easy</p><p><strong>Integration: </strong>Works well with databases (MongoDB, MySQL), authentication (JWT)</p><p><strong>Minimal Setup: </strong>You can write a basic web server in just 4–5 lines</p><h3>Simple Express.js Example</h3><pre>const express = require(&#39;express&#39;);<br>const app = express();<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello, Mahadev!&#39;);<br>});<br>app.listen(3000, () =&gt; {<br>  console.log(&#39;Server running on http://localhost:3000&#39;);<br>});</pre><p>🟢 Run this, open your browser, and you’ll see <strong>“Hello, Mahadev!”</strong> on <a href="http://localhost:3000.">http://localhost:3000</a></p><h3>📦 How to Install Express:</h3><pre>npm init -y<br>npm install express</pre><h3>Use Cases:</h3><ul><li>REST APIs (e.g., for mobile or React apps)</li><li>Admin dashboards</li><li>Authentication systems</li><li>Blogging engines</li><li>Ecommerce backends</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=09e1a51d8ad2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why should we use typescript over javascript?]]></title>
            <link>https://medium.com/@rastogi.programmer/why-should-we-use-typescript-over-javascript-618f45b653e3?source=rss-a508adfb19bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/618f45b653e3</guid>
            <dc:creator><![CDATA[Vivek Rastogi]]></dc:creator>
            <pubDate>Thu, 17 Jul 2025 15:53:24 GMT</pubDate>
            <atom:updated>2025-07-17T15:53:24.847Z</atom:updated>
            <content:encoded><![CDATA[<p>TypeScript is a superset of JavaScript that adds static typing, interfaces, and modern ECMAScript features</p><h3>1. Type Safety</h3><p>TypeScript adds <strong>static type checking</strong>, which catches errors at <strong>compile time</strong> instead of at runtime.</p><ul><li><strong>JavaScript</strong>: let user = {}; user.name.toUpperCase(); // Runtime error</li><li><strong>TypeScript</strong>: Property &#39;name&#39; does not exist on type &#39;{}&#39; → Error shown during development.</li></ul><p><strong>Benefit</strong>: Fewer bugs, more predictable code.</p><h3>2. Static Typing</h3><p>TypeScript allows you to define variable types, catching errors <strong>at compile time</strong>.</p><p><strong>Example:</strong></p><pre>function add(a: number, b: number): number {<br>  return a + b;<br>}</pre><pre>add(5, &quot;10&quot;); // ❌ Error: Argument of type &#39;string&#39; is not assignable to parameter of type &#39;number&#39;</pre><p><strong>Advantage:</strong> Prevents type-related bugs early, especially in large projects.</p><h3>3. Better Code Completion and IntelliSense</h3><p>TypeScript provides better auto-complete and suggestions in editors like VS Code.</p><p><strong>Example:</strong></p><pre>interface User {<br>  id: number;<br>  name: string;<br>}<br><br>const user: User = { id: 1, name: &quot;Vivek&quot; };<br>// Typing `user.` will show IntelliSense with `id` and `name` properties</pre><p><strong>Advantage:</strong> Increases productivity and reduces errors.</p><h3>4. Scalability</h3><p>TypeScript is ideal for <strong>large-scale applications</strong> and team projects, where strict types enforce consistency and reduce regressions.</p><h3>5. Object-Oriented Programming (OOP) Support</h3><p>TypeScript supports <strong>classes, interfaces, inheritance</strong>, and access modifiers.</p><p><strong>Example:</strong></p><pre>class Animal {<br>  constructor(public name: string) {}<br>  move() {<br>    console.log(`${this.name} moves.`);<br>  }<br>}<br><br>class Dog extends Animal {<br>  bark() {<br>    console.log(&quot;Woof!&quot;);<br>  }<br>}<br><br>const dog = new Dog(&quot;Tommy&quot;);<br>dog.move(); // Tommy moves.<br>dog.bark(); // Woof!</pre><pre><strong>Advantage:</strong> Encourages reusable, scalable design.</pre><h3>6. Optional and Default Parameters</h3><p>Improves function usability and documentation.</p><p><strong>Example:</strong></p><pre>function greet(name: string = &quot;Guest&quot;) {<br>  console.log(`Hello, ${name}`);<br>}<br><br>greet();         // Hello, Guest<br>greet(&quot;Vivek&quot;);  // Hello, Vivek</pre><h3>7. Tooling and IDE Integration</h3><p>TS compiler can highlight dead code, unreachable code, and provide suggestions.</p><p><strong>Example:</strong></p><pre>function calculate(): number {<br>  return;<br>}<br>// ❌ Warning: Function lacks return statement</pre><h3>8. Compatibility with JavaScript</h3><p>You can gradually migrate JS to TS.</p><p><strong>Example:</strong></p><pre>// Valid JS code<br>let age = 25;<br><br>// In TS you can add types<br>let age: number = 25;</pre><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=618f45b653e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>