<?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"><channel><title><![CDATA[Creating Routes and Handling Requests with Express]]></title><description><![CDATA[Creating Routes and Handling Requests with Express]]></description><link>https://route-handling-in-express.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 07:52:27 GMT</lastBuildDate><atom:link href="https://route-handling-in-express.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Creating Routes and Handling Requests with Express
]]></title><description><![CDATA[What is Express.js?
Express.js is a fast, minimal, and popular web framework for Node.js. It helps developers build web servers and APIs more easily than using the raw Node.js http module.
With Expres]]></description><link>https://route-handling-in-express.hashnode.dev/creating-routes-and-handling-requests-with-express</link><guid isPermaLink="true">https://route-handling-in-express.hashnode.dev/creating-routes-and-handling-requests-with-express</guid><category><![CDATA[creating-routes-and-handling-requests-with-express]]></category><category><![CDATA[how to handle routes in express]]></category><category><![CDATA[Methods on express]]></category><category><![CDATA[express routes]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[@hiteshchoudharylco]]></category><category><![CDATA[#piyushgarag]]></category><dc:creator><![CDATA[Ritu Sood]]></dc:creator><pubDate>Wed, 29 Apr 2026 18:23:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696e5fe3e1b3dda793831d69/c84f03f3-114a-4c6f-b0de-bde054908184.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What is Express.js?</h2>
<p><strong>Express.js</strong> is a fast, minimal, and popular web framework for <strong>Node.js</strong>. It helps developers build web servers and APIs more easily than using the raw Node.js <code>http</code> module.</p>
<p>With Express, you can:</p>
<ul>
<li><p>Create servers quickly</p>
</li>
<li><p>Handle routes easily</p>
</li>
<li><p>Manage GET, POST, PUT, DELETE requests</p>
</li>
<li><p>Send responses simply</p>
</li>
<li><p>Build REST APIs faster</p>
</li>
</ul>
<p>👉 In simple words:</p>
<blockquote>
<p>Node.js gives the engine.<br />Express gives the steering wheel.</p>
</blockquote>
<hr />
<h3>Why Express Simplifies Node.js Development</h3>
<p>Using plain Node.js for routing can become repetitive and messy.</p>
<h3>Raw Node.js Example</h3>
<pre><code class="language-javascript">const http = require("http");

const server = http.createServer((req, res) =&gt; {
  if (req.url === "/") {
    res.end("Home Page");
  } else if (req.url === "/about") {
    res.end("About Page");
  }
});

server.listen(3000);
</code></pre>
<p>You manually check URLs and methods.</p>
<hr />
<h3>Express Example</h3>
<pre><code class="language-javascript">const express = require("express");
const app = express();

app.get("/", (req, res) =&gt; {
  res.send("Home Page");
});

app.get("/about", (req, res) =&gt; {
  res.send("About Page");
});

app.listen(3000);
</code></pre>
<p>Cleaner, shorter, and easier to manage.</p>
<hr />
<h3>Creating Your First Express Server</h3>
<p><strong>Step 1: Install Express</strong></p>
<pre><code class="language-javascript">npm install express
</code></pre>
<p><strong>Step 2: Create</strong> <code>server.js</code></p>
<pre><code class="language-javascript">const express = require("express");
const app = express();

app.listen(3000, () =&gt; {
  console.log("Server running on port 3000");
});
</code></pre>
<p><strong>Step 3: Run Server</strong></p>
<pre><code class="language-javascript">node server.js
</code></pre>
<h3>Understanding Routes</h3>
<p>A <strong>route</strong> is a path + HTTP method.</p>
<p>Examples:</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Route</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td>GET</td>
<td><code>/</code></td>
<td>Fetch homepage</td>
</tr>
<tr>
<td>GET</td>
<td><code>/users</code></td>
<td>Get users</td>
</tr>
<tr>
<td>POST</td>
<td><code>/users</code></td>
<td>Create user</td>
</tr>
</tbody></table>
<p>👉 Route decides what happens when client hits a URL.</p>
<hr />
<h3>Handling GET Requests</h3>
<p>GET is used to <strong>fetch data</strong>.</p>
<pre><code class="language-javascript">app.get("/products", (req, res) =&gt; {
  res.send("List of Products");
});
</code></pre>
<p>When user opens:</p>
<pre><code class="language-plaintext">http://localhost:3000/products
</code></pre>
<p>Server responds:</p>
<pre><code class="language-plaintext">List of Products
</code></pre>
<hr />
<h3>Handling POST Requests</h3>
<p>POST is used to <strong>send/create data</strong>.</p>
<pre><code class="language-javascript">app.post("/users", (req, res) =&gt; {
  res.send("User Created");
});
</code></pre>
<p>Used in forms, signup pages, APIs, etc.</p>
<hr />
<h3>Sending Responses</h3>
<p>Express provides easy response methods.</p>
<h3>Text Response</h3>
<pre><code class="language-plaintext">res.send("Hello World");
</code></pre>
<h3>JSON Response</h3>
<pre><code class="language-javascript">res.json({ name: "Ritu", role: "Developer" });
</code></pre>
<h3>Status Code Response</h3>
<pre><code class="language-javascript">res.status(404).send("Page Not Found");
</code></pre>
<hr />
<h3>Full Example</h3>
<pre><code class="language-javascript">const express = require("express");
const app = express();

app.get("/", (req, res) =&gt; {
  res.send("Welcome Home");
});

app.get("/about", (req, res) =&gt; {
  res.send("About Us");
});

app.post("/contact", (req, res) =&gt; {
  res.send("Form Submitted");
});

app.listen(3000, () =&gt; {
  console.log("Server Started");
});
</code></pre>
<h3>Request → Route Handler → Response Flow</h3>
<pre><code class="language-javascript">Browser / Client Request
        ↓
   Express Route Match
        ↓
   Route Handler Runs
        ↓
   Response Sent Back
</code></pre>
<h3>Express Routing Structure</h3>
<pre><code class="language-javascript">app.get("/users", handler)
app.post("/users", handler)
app.get("/products", handler)
app.delete("/products/:id", handler)
</code></pre>
<p>Each route handles a specific request.</p>
<hr />
<h3>Why Developers Love Express</h3>
<ol>
<li><strong>Easy Routing</strong></li>
</ol>
<p>Simple methods like:</p>
<p><code>app.get()</code></p>
<p><code>app.post()</code></p>
<p><strong>2. Fast API Development</strong></p>
<p>Build backend quickly.</p>
<p><strong>3 . Middleware Support</strong></p>
<p>Add authentication, logging, parsing.</p>
<p><strong>4 . Huge Community</strong></p>
<p>Lots of tutorials and packages.</p>
<hr />
<h3>Raw Node.js vs Express</h3>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Raw Node.js</th>
<th>Express</th>
</tr>
</thead>
<tbody><tr>
<td>Routing</td>
<td>Manual</td>
<td>Easy</td>
</tr>
<tr>
<td>Code Length</td>
<td>More</td>
<td>Less</td>
</tr>
<tr>
<td>Readability</td>
<td>Medium</td>
<td>High</td>
</tr>
<tr>
<td>API Development</td>
<td>Slower</td>
<td>Faster</td>
</tr>
</tbody></table>
<hr />
<h3>Final Thoughts</h3>
<p>Express.js makes Node.js backend development much easier.</p>
<p>Instead of manually handling URLs and responses, Express gives you a clean routing system.</p>
<p>That’s why Express is one of the most popular Node.js frameworks for building:</p>
<p>1 . Websites</p>
<p>2 . REST APIs</p>
<p>3 . Admin Panels</p>
<p>4 . Backend Services</p>
<hr />
<h2>Quick Summary</h2>
<ul>
<li><p>Express.js is a framework for Node.js</p>
</li>
<li><p>Simplifies server creation</p>
</li>
<li><p>Makes routing easy</p>
</li>
<li><p>Supports GET and POST requests</p>
</li>
<li><p>Easy response handling</p>
</li>
<li><p>Great for APIs and web apps</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>