<?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[Harianant Sinha's Blog]]></title><description><![CDATA[Harianant Sinha's Blog]]></description><link>https://harianantsinha.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 05 Oct 2026 16:12:28 GMT</lastBuildDate><atom:link href="https://harianantsinha.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[From Setback to Success: Mastering Backend Web Development After Revoked Offers]]></title><description><![CDATA[🌱 Introduction
My job offer got revoked this spring💔. It stung, but instead of folding, I decided to double-down on learning web development.
Frontend was my comfort zone — backend? Total jungle. 🐒 I walked in and saw tech names flying everywhere:...]]></description><link>https://harianantsinha.hashnode.dev/from-setback-to-success-mastering-backend-web-development-after-revoked-offers</link><guid isPermaLink="true">https://harianantsinha.hashnode.dev/from-setback-to-success-mastering-backend-web-development-after-revoked-offers</guid><category><![CDATA[tech journey]]></category><category><![CDATA[software development]]></category><category><![CDATA[software architecture]]></category><category><![CDATA[backend]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[jobs]]></category><category><![CDATA[job search]]></category><category><![CDATA[learning]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Node.js]]></category><dc:creator><![CDATA[Harianant Sinha]]></dc:creator><pubDate>Fri, 08 Aug 2025 11:25:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1754388234828/98f6dbe5-60c2-4cc8-a6f9-ffa3269f02cd.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">🌱 Introduction</h2>
<p>My job offer got revoked this spring💔. It stung, but instead of folding, I decided to <strong>double-down on learning web development</strong>.</p>
<p>Frontend was my comfort zone — backend? Total jungle. 🐒 I walked in and saw tech names flying everywhere: JWT, <strong>Express</strong>, <strong>MongoDB</strong>, <strong>WebSockets</strong>… it felt like I’d need a map just to survive.</p>
<p>Today, I took one step forward: learning <strong>WebSockets</strong> — a small but essential piece of the real-time app puzzle.</p>
<hr />
<h2 id="heading-facing-the-backend-beast">😅 Facing the Backend Beast</h2>
<p>When I first peeked into backend development, it felt like walking into a library where all the books were written in different languages — <strong>Express</strong>, <strong>JWT</strong>, <strong>MongoDB</strong>, <strong>WebSockets</strong>… I didn’t even know where to start. My brain wanted to stick with the pretty buttons and colors of frontend. But I knew that if I wanted to build <em>complete</em> applications, I had to make peace with the backend. So I started small, tackling one technology at a time — no rush, just steady progress. Today’s battle? WebSockets. ⚔️</p>
<hr />
<h2 id="heading-what-is-websocket">⚡ What is WebSocket?</h2>
<p>WebSockets give you a <strong>persistent, full-duplex connection</strong> between browser and server — unlike HTTP’s request/response model.</p>
<p>Once connected, both sides can send messages anytime. Perfect for 💬 chats, 📊 live dashboards, and 🎮 multiplayer games.</p>
<hr />
<h2 id="heading-how-it-works-quick">🧩 How It Works (Quick)</h2>
<ul>
<li><p><strong>Client-side:</strong> In the browser, you create a <code>socket</code>:</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> socket = <span class="hljs-keyword">new</span> WebSocket(<span class="hljs-string">'ws://localhost:8080'</span>);
</code></pre>
</li>
<li><p><strong>Server-side:</strong> With Node.js + <code>ws</code> library, you listen for connections:</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> WebSocket = <span class="hljs-built_in">require</span>(<span class="hljs-string">'ws'</span>);
  <span class="hljs-keyword">const</span> server = <span class="hljs-keyword">new</span> WebSocket.Server({ <span class="hljs-attr">port</span>: <span class="hljs-number">8080</span> });
</code></pre>
  <div data-node-type="callout">
  <div data-node-type="callout-emoji">💡</div>
  <div data-node-type="callout-text">Messages are simply data exchanged between the client and server.</div>
  </div>


</li>
</ul>
<h2 id="heading-what-i-built-today-3-levels-of-websocket-learning">🚀 What I Built Today — 3 Levels of WebSocket Learning</h2>
<h3 id="heading-1-basic-broadcast-messages-to-everyone">1️⃣ Basic — Broadcast Messages to Everyone</h3>
<p><strong>Goal</strong>: Every incoming message to the server is broadcast to all connected clients.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Broadcasting the message recieved to all the open clients</span>
wss.on(<span class="hljs-string">"connection"</span>, <span class="hljs-function">(<span class="hljs-params">ws</span>) =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Client connected."</span>);
    ws.on(<span class="hljs-string">"message"</span>, <span class="hljs-function">(<span class="hljs-params">message</span>) =&gt;</span> {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Received from one client: %s"</span>, message);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Broadcasting message to all clients..."</span>);
        <span class="hljs-comment">// Iterate over every client connected to the server</span>
        wss.clients.forEach(<span class="hljs-function">(<span class="hljs-params">client</span>) =&gt;</span> {
            <span class="hljs-comment">// Check if the client is not the sender and is ready to receive messages</span>
            <span class="hljs-keyword">if</span> (client.readyState === ws.OPEN) {
                <span class="hljs-comment">// Send the message to all clients </span>
                client.send(message.toString());
            }
        });
    });
});
</code></pre>
<p>✅ It worked immediately—my first "real-time client-server communication" moment! 🎉</p>
<hr />
<h3 id="heading-2-intermediate-dont-echo-to-sender">2️⃣ Intermediate — Don’t Echo to Sender</h3>
<p>Goal: Build a simple chat app that broadcasts a client's message to all other active clients, excluding the sender.</p>
<pre><code class="lang-javascript">wss.on(<span class="hljs-string">"connection"</span>, <span class="hljs-function">(<span class="hljs-params">ws</span>) =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Client connected."</span>);
    ws.on(<span class="hljs-string">"message"</span>, <span class="hljs-function">(<span class="hljs-params">message</span>) =&gt;</span> {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Received from one client: %s"</span>, message);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Broadcasting message to all clients..."</span>);
        <span class="hljs-comment">// Iterate over every client connected to the server</span>
        wss.clients.forEach(<span class="hljs-function">(<span class="hljs-params">client</span>) =&gt;</span> {
            <span class="hljs-comment">// Check if the client is not the sender and is ready to receive messages</span>
            <span class="hljs-keyword">if</span> (client.readyState === WebSocket.OPEN &amp;&amp; client!==ws) {
                <span class="hljs-comment">// Send the message to THIS client in the loop</span>
                client.send(<span class="hljs-string">`Message from sender: <span class="hljs-subst">${message.toString()}</span>`</span>);
            }
        });
    });
});
</code></pre>
<hr />
<h3 id="heading-3-advanced-unique-ids-amp-disconnect-alerts">3️⃣ Advanced — Unique IDs &amp; Disconnect Alerts</h3>
<p>Goal: Create an intermediate Chat App where each client has a unique ID</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// For this I shall use Uuid package for generating the user id:</span>
<span class="hljs-keyword">const</span> { <span class="hljs-attr">v4</span>: uuidv4 } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'uuid'</span>);
</code></pre>
<p>Messages now look like:</p>
<blockquote>
<p>Received message from client 02ad354e-8232-46f1-b546-020b1f923e97: Hello, this is message from client</p>
</blockquote>
<p>When a client disconnects, the server broadcasts:</p>
<blockquote>
<p>Client 02ad354e-8232-46f1-b546-020b1f923e97 disconnected</p>
</blockquote>
<p>Putting it all together:</p>
<pre><code class="lang-javascript">wss.on(<span class="hljs-string">"connection"</span>,<span class="hljs-function">(<span class="hljs-params">ws</span>)=&gt;</span>{
    ws.id = uuidv4();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Client connected with ID: <span class="hljs-subst">${ws.id}</span>`</span>);
    ws.on(<span class="hljs-string">"message"</span>, <span class="hljs-function">(<span class="hljs-params">message</span>) =&gt;</span> {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Received message from client <span class="hljs-subst">${ws.id}</span>:  <span class="hljs-subst">${message}</span>`</span>);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Broadcasting message to all clients..."</span>);
        <span class="hljs-comment">// Iterate over every client connected to the server</span>
        wss.clients.forEach(<span class="hljs-function">(<span class="hljs-params">client</span>) =&gt;</span> {
            <span class="hljs-comment">// Check if the client is not the sender and is ready to receive messages</span>
            <span class="hljs-keyword">if</span> (client.readyState === WebSocket.OPEN &amp;&amp; client!==ws) {
                <span class="hljs-comment">// Send the message to THIS client in the loop</span>
                client.send(<span class="hljs-string">`Message from sender <span class="hljs-subst">${ws.id}</span>: <span class="hljs-subst">${message.toString()}</span>`</span>);
            }
        });
    });
    ws.on(<span class="hljs-string">'close'</span>, <span class="hljs-function">() =&gt;</span> {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Client <span class="hljs-subst">${ws.id}</span> disconnected.`</span>);
        <span class="hljs-comment">// Broadcast the disconnect message to all remaining clients</span>
        wss.clients.forEach(<span class="hljs-function"><span class="hljs-params">client</span> =&gt;</span> {
            <span class="hljs-keyword">if</span> (client.readyState === WebSocket.OPEN) {
                client.send(<span class="hljs-string">`User <span class="hljs-subst">${ws.id}</span> has left the chat.`</span>);
            }
        });
    });
})
</code></pre>
<p>Suddenly it’s not just “<em>data</em>” — it feels like people coming and going. 🧑‍🤝‍🧑</p>
<hr />
<h2 id="heading-wrap-up-takeaway">💡 Wrap-Up / Takeaway</h2>
<p><strong>Big insight:</strong> <em>Managing connections is as important as sending data.</em> IDs, states, and disconnect handling turn sockets from pipes into conversations.</p>
<p>Backend was my biggest fear — too many tech names, too many moving parts — but breaking it into small levels made progress steady and fun.</p>
<p>Next stop: adding <strong>JWT authentication</strong> and storing messages in <strong>MongoDB</strong> so the chat history survives page reloads. 🚀</p>
<p>If you’ve had a setback or wrestled with backend concepts, let’s swap notes! 🤝</p>
<hr />
<h2 id="heading-ps-my-engineering-diary">📓 PS – My Engineering Diary</h2>
<p>Every day, I log exactly what I learn — topics, difficulties, breakthroughs — in a simple markdown file. I even have a tiny script that creates the daily template for me (one command, done ✅).</p>
<p>If you’re curious to see <em>every</em> step of this backend learning journey — not just the highlights — you can browse the full diary here:</p>
<p><a target="_blank" href="https://github.com/Hsinha11/My-Engineering-Diary">📂 My Engineering Diary on GitHub</a></p>
<p>📬 <strong>Like this post?</strong> Subscribe so you don’t miss the next step in the journey — I’m posting every win, fail along the way.</p>
]]></content:encoded></item></channel></rss>