<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rohit Giri</title>
    <description>The latest articles on DEV Community by Rohit Giri (@rohit_giri).</description>
    <link>https://dev.to/rohit_giri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3734032%2Ffa85752b-8327-49be-89e8-69945a838f57.png</url>
      <title>DEV Community: Rohit Giri</title>
      <link>https://dev.to/rohit_giri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rohit_giri"/>
    <language>en</language>
    <item>
      <title>Nodejs : from Hate to love</title>
      <dc:creator>Rohit Giri</dc:creator>
      <pubDate>Sun, 07 Jun 2026 04:35:23 +0000</pubDate>
      <link>https://dev.to/rohit_giri/nodejs-from-hate-to-love-2i7j</link>
      <guid>https://dev.to/rohit_giri/nodejs-from-hate-to-love-2i7j</guid>
      <description>&lt;p&gt;"simplicity is the ultimate sophistication" by &lt;strong&gt;"leonardo da vinci"&lt;/strong&gt;.To understand it I spend a lot of my precious time. I was the guy who was curious about the technology when nobody around me cares about it. When i started to learn web i found that there is the one ultimate language that is essential to learn is javascript initially it was suck. Every one who used javascript knows about it. for those who dont know let me give you examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="c1"&gt;// ""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both arrays become empty strings during type coercion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="c1"&gt;// "[object Object]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="c1"&gt;// 0  &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the first {} can be interpreted as an empty block, not an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;
&lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because NaN is defined as “not equal to anything, including itself.”&lt;/p&gt;

&lt;p&gt;for a learner it was very difficult to understand all these things because at first they do not make any sense. &lt;br&gt;
By the time the frustration suddenly start making sense and the hate for javascript became love. &lt;/p&gt;
&lt;h2&gt;
  
  
  From Frustration to Love: The Node.js Features That Changed Everything
&lt;/h2&gt;

&lt;p&gt;There's a specific moment every developer knows — the one where JavaScript stops being the enemy and starts making sense. Where the chaos of callbacks and the weirdness of &lt;code&gt;this&lt;/code&gt; suddenly clicks, and you realize the language wasn't broken. You just hadn't seen it from the right angle yet.&lt;/p&gt;

&lt;p&gt;For me, that angle was the backend. Specifically, Node.js.&lt;/p&gt;

&lt;p&gt;I chose Node.js as my go-to when I started learning backend development, and it wasn't a random pick. The more I worked with it, the more I found myself genuinely &lt;em&gt;excited&lt;/em&gt; about how it operates under the hood. So let me walk you through the three features that made me fall in love with it — not as bullet points in a docs page, but as real ideas worth understanding.&lt;/p&gt;


&lt;h2&gt;
  
  
  1. The Event Loop — Node's Beating Heart
&lt;/h2&gt;

&lt;p&gt;If you've ever been told "JavaScript is single-threaded," you probably followed that up with a confused — &lt;em&gt;"then how does it handle thousands of requests?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That's the Event Loop doing its job.&lt;/p&gt;

&lt;p&gt;Node.js is built on a reactor pattern. At its core, there's a single-threaded event loop backed by a non-blocking I/O model, powered by &lt;strong&gt;libuv&lt;/strong&gt; under the hood. Instead of spinning up a new thread for every incoming request (the way traditional servers like Apache do), Node registers an event handler and moves on. When the I/O operation completes — a database query, a file read, a network call — the result is pushed into the event queue. The event loop picks it up and runs your callback.&lt;/p&gt;

&lt;p&gt;Here's what that looks like in practice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data.txt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;File contents:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;End&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start
End
File contents: ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that &lt;code&gt;End&lt;/code&gt; prints &lt;em&gt;before&lt;/em&gt; the file is read. Node didn't sit around waiting. It registered the callback, kept moving, and came back when the file was ready. This is non-blocking I/O in its simplest form.&lt;/p&gt;

&lt;p&gt;The event loop itself cycles through multiple phases — timers, pending callbacks, idle, poll, check, and close callbacks — in a precise order. The &lt;strong&gt;poll phase&lt;/strong&gt; is where the loop waits for new I/O events. The &lt;strong&gt;check phase&lt;/strong&gt; is where &lt;code&gt;setImmediate()&lt;/code&gt; callbacks run. Understanding this order is what separates developers who &lt;em&gt;use&lt;/em&gt; Node from those who truly &lt;em&gt;understand&lt;/em&gt; it.&lt;/p&gt;

&lt;p&gt;This architecture is why Node.js can handle tens of thousands of concurrent connections with a fraction of the memory a thread-per-request model would need. It's not magic — it's a very deliberate design choice, and it's one of the most elegant ideas in modern server-side development.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Module System — Building Blocks, Your Way
&lt;/h2&gt;

&lt;p&gt;Every serious application is just well-organized modules talking to each other. Node.js understood this early, and the module system it offers gives you both structure and flexibility.&lt;/p&gt;

&lt;p&gt;Node originally used &lt;strong&gt;CommonJS&lt;/strong&gt; (&lt;code&gt;require&lt;/code&gt; / &lt;code&gt;module.exports&lt;/code&gt;), and it still works beautifully. The modern ecosystem has also embraced &lt;strong&gt;ES Modules&lt;/strong&gt; (&lt;code&gt;import&lt;/code&gt; / &lt;code&gt;export&lt;/code&gt;). But beyond the syntax, what's interesting is &lt;em&gt;how&lt;/em&gt; you design your modules — and the patterns you can apply.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Basic CommonJS Module
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// greet.js&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;! Welcome to Node.js.`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./greet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Arjun&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clean, simple, predictable. But now let's go deeper.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 1 — The Singleton Module
&lt;/h3&gt;

&lt;p&gt;In Node.js, modules are cached after the first &lt;code&gt;require()&lt;/code&gt;. This means that every time you import the same module, you get the &lt;em&gt;same instance&lt;/em&gt;. This is the singleton pattern, built right into the runtime — for free.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mongodb://localhost:27017/myapp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No matter how many files &lt;code&gt;require('./config')&lt;/code&gt;, they all share the same object. Change a property in one place, and it reflects everywhere. This is incredibly useful for shared state like database connections or application configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 2 — The Factory Module
&lt;/h3&gt;

&lt;p&gt;Sometimes you don't want a singleton. You want the module to &lt;em&gt;create&lt;/em&gt; something fresh each time it's called. That's the factory pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// logger.js&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;log&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] ERROR: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createLogger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createLogger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./logger&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authLogger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Auth&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dbLogger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Database&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;authLogger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User logged in&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dbLogger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Connection failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have independent loggers, each with their own context — all from the same module file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 3 — The Revealing Module Pattern
&lt;/h3&gt;

&lt;p&gt;This pattern lets you control exactly what's public and what stays private, mimicking class-level encapsulation without needing a class at all.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// counter.js&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getCount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getCount&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;count&lt;/code&gt; is private — nobody outside this module can directly mutate it. They can only interact through the exposed API. This is clean, safe, and exactly how well-designed libraries work.&lt;/p&gt;

&lt;p&gt;The module system isn't just a convenience — it's an architectural tool. Learning to design modules intentionally is what takes a Node project from a pile of files to something maintainable and scalable.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Full-Stack JavaScript — The Unfair Advantage
&lt;/h2&gt;

&lt;p&gt;This one doesn't get talked about enough.&lt;/p&gt;

&lt;p&gt;When you write a Python or Ruby backend, you're working in one language on the server and JavaScript on the client. That means two mental models, two sets of tooling, two type systems (or lack thereof), and inevitable translation overhead when data moves between them.&lt;/p&gt;

&lt;p&gt;Node.js removes that boundary entirely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shared Code Between Frontend and Backend
&lt;/h3&gt;

&lt;p&gt;Here's a real example. Say you have form validation logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// shared/validators.js&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isValidEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[^\s&lt;/span&gt;&lt;span class="sr"&gt;@&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+@&lt;/span&gt;&lt;span class="se"&gt;[^\s&lt;/span&gt;&lt;span class="sr"&gt;@&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;\.[^\s&lt;/span&gt;&lt;span class="sr"&gt;@&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+$/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isStrongPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isValidEmail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isStrongPassword&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This exact file can be imported in your Express API to validate request bodies &lt;em&gt;and&lt;/em&gt; bundled into your React or Vue frontend to validate forms before submission. One source of truth. Zero duplication.&lt;/p&gt;

&lt;p&gt;In Python, you'd write this logic twice — once in Python for the server, once in JavaScript for the browser. Every time the rules change, you update two places and hope they stay in sync.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSON is Native
&lt;/h3&gt;

&lt;p&gt;JavaScript and JSON share the same DNA — JSON literally stands for &lt;strong&gt;JavaScript Object Notation&lt;/strong&gt;. When your Node.js backend fetches data from a database and sends it to a React frontend, there's no serialization friction. Objects flow naturally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Express API&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Plain JS object → JSON response, zero effort&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// React Frontend&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user/42&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Back to a plain JS object&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare this to Python's Flask or Django, where you often need to define serializers, handle type conversions, and map between Python data structures and JSON representations. It's doable, but it adds layers. With Node.js, there are no layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  One Language, One Team
&lt;/h3&gt;

&lt;p&gt;For startups and small teams especially, this is transformative. A frontend developer can contribute to the backend without switching languages. A backend developer can fix a UI bug without re-learning syntax. Code reviews become easier because everyone can read everything.&lt;/p&gt;

&lt;p&gt;This is an advantage that no other backend language can honestly claim — because no other language &lt;em&gt;is&lt;/em&gt; the browser's language.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bigger Picture
&lt;/h2&gt;

&lt;p&gt;Node.js won me over not because it's the easiest tool or the most feature-rich. It won me over because it's &lt;em&gt;coherent&lt;/em&gt;. The event loop is a logical response to I/O-bound workloads. The module system gives you just enough structure without imposing a rigid framework. And full-stack JavaScript isn't just a convenience — it's a genuine competitive advantage.&lt;/p&gt;

&lt;p&gt;The hate for JavaScript makes sense in hindsight. We encounter it first in the browser, in its messiest, most inconsistent form — DOM manipulation, browser quirks, the infamous &lt;code&gt;this&lt;/code&gt;. But Node.js gave JavaScript a second context, a cleaner one, with real tooling and a clear purpose.&lt;/p&gt;

&lt;p&gt;And that's when the frustration started making sense.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;for those who says nodejs has lot of issues like we say in hindi "दाग तो चाँद में भी होते हैं।" Even the moon has scars. That never stopped anyone from looking up.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>If you're a backend developer, understanding HTTP deeply will make debugging 10x easier.</title>
      <dc:creator>Rohit Giri</dc:creator>
      <pubDate>Sun, 01 Feb 2026 07:31:39 +0000</pubDate>
      <link>https://dev.to/rohit_giri/if-youre-a-backend-developer-understanding-http-deeply-will-make-debugging-10x-easier-2647</link>
      <guid>https://dev.to/rohit_giri/if-youre-a-backend-developer-understanding-http-deeply-will-make-debugging-10x-easier-2647</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/rohit_giri" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3734032%2Ffa85752b-8327-49be-89e8-69945a838f57.png" alt="rohit_giri"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/rohit_giri/backend-without-http-how-would-the-web-work-e26" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Backend Without HTTP: How Would the Web Work?&lt;/h2&gt;
      &lt;h3&gt;Rohit Giri ・ Feb 1&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#backend&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#networking&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Backend Without HTTP: How Would the Web Work?</title>
      <dc:creator>Rohit Giri</dc:creator>
      <pubDate>Sun, 01 Feb 2026 07:28:46 +0000</pubDate>
      <link>https://dev.to/rohit_giri/backend-without-http-how-would-the-web-work-e26</link>
      <guid>https://dev.to/rohit_giri/backend-without-http-how-would-the-web-work-e26</guid>
      <description>&lt;p&gt;Ever wondered what life without HTTP (HyperText Transfer Protocol) would look like?&lt;br&gt;
It would feel like trying to send a letter without a postman — you have a message, but no reliable way to deliver it to the right place.&lt;/p&gt;

&lt;p&gt;To truly understand that, we first need to answer a simple question:&lt;/p&gt;

&lt;p&gt;What is HTTP?&lt;/p&gt;

&lt;p&gt;And no — not the boring “it stands for HyperText Transfer Protocol” answer&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore HTTP from a low-level perspective: how it actually works behind the scenes, how requests and responses travel, and what really happens when you type a URL and hit Enter. &lt;/p&gt;
&lt;h2&gt;
  
  
  How Do Computers Communicate?
&lt;/h2&gt;

&lt;p&gt;Before we understand HTTP (a protocol used to send data on the web), we first need to understand how computers actually communicate.&lt;/p&gt;

&lt;p&gt;Imagine you want to send a message from Person A to Person B. There can be two situations:&lt;/p&gt;

&lt;p&gt;Both live in the same house&lt;br&gt;
→ Communication is easy and direct.&lt;/p&gt;

&lt;p&gt;They live in different houses&lt;br&gt;
→ You need a proper addressing system so the message reaches the correct destination.&lt;/p&gt;

&lt;p&gt;Computers work in a very similar way.&lt;/p&gt;

&lt;p&gt;In networking, communication also happens in two common scenarios:&lt;/p&gt;

&lt;p&gt;1) Devices are in the same network (same local area network / same router)&lt;/p&gt;

&lt;p&gt;2) Devices are in different networks (across cities or countries)&lt;/p&gt;

&lt;p&gt;To make sure the message reaches the correct device, every device needs an address.&lt;/p&gt;

&lt;p&gt;That address is called an &lt;strong&gt;IP Address&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;👉 Think of an IP address like your house address — it tells the network where exactly to deliver the data.&lt;/p&gt;
&lt;h2&gt;
  
  
  what makes HTTP unique
&lt;/h2&gt;

&lt;p&gt;there are a lot of things that are great but one thing that i like the most  it is &lt;strong&gt;stateless&lt;/strong&gt;. Stateless means that it has no memory of past interactions every request is treated as a new request. It simplify the server architecture by not storing session information. Now you will say how the hell developer handle the state management. I said state will not be managed by the server that does not mean it will not be managed by client also, developer can manage the state by storing all necessary information in &lt;strong&gt;cookies&lt;/strong&gt;, &lt;strong&gt;session&lt;/strong&gt; and &lt;strong&gt;tokens&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Client Server model
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc17qxr0d2x2jduv8m2zz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc17qxr0d2x2jduv8m2zz.png" alt="Http client server model diagram" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Http works on client server model, Where client send Http request and server respond with Http response.&lt;/p&gt;
&lt;h2&gt;
  
  
  Evolution of HTTP
&lt;/h2&gt;

&lt;p&gt;HTTP 1.0: Opened a new connection for each request, leading to inefficiencies.&lt;/p&gt;

&lt;p&gt;HTTP 1.1: Introduced persistent connections, allowing multiple requests and responses over a single TCP connection, significantly improving performance. It also added chunk transfer encoding and better caching mechanisms.&lt;/p&gt;

&lt;p&gt;HTTP 2.0: Introduced multiplexing, allowing multiple requests/responses over a single connection using binary framing instead of text. It supports header compression and server push.&lt;/p&gt;

&lt;p&gt;HTTP 3.0: Built on the QUIC protocol (over UDP) for faster connection establishment, reduced latency, and better packet loss handling. It continues to support multiplexing without head-of-line blocking.&lt;/p&gt;
&lt;h2&gt;
  
  
  HTTP Request Send By Client
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;method&amp;gt; &amp;lt;request-target&amp;gt; &amp;lt;protocol&amp;gt;
&amp;lt;request-headers&amp;gt;
&amp;lt;representational-headers&amp;gt;
&amp;lt;request-body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Method&lt;/strong&gt;&lt;br&gt;
    it can be GET, POST, PUT etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;request-target&lt;/strong&gt;&lt;br&gt;
    it can be absolute or relative URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;protocol&lt;/strong&gt;&lt;br&gt;
    The HTTP version it can be any that we have discussed above like HTTP 1.0,HTTP 2.0 etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;request-headers&lt;/strong&gt;&lt;br&gt;
Headers are metadata sent with a request after the start line and before the body. refer the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;representational-headers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Representation headers are sent in a request if the message has a body, and they describe the original form of the message data and any encoding applied. this is very important for the recipient to understand how to handle the body part of the request properly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Content-Type: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Request-Body&lt;/strong&gt;&lt;br&gt;
Typically Only PATCH, POST, and PUT requests have a body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "firstName": "Rohit",
  "lastName": "Giri",
  "email": "rg123@ai.com",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Request body can contain additional information required by the server to process any request.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP Response Send By Server
&lt;/h2&gt;

&lt;p&gt;A wise man said that if you understand the response send by the server you can debug any Http request and response. By the way i said this 😅.&lt;/p&gt;

&lt;p&gt;below is the Wireframe of Http response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;protocol&amp;gt; &amp;lt;status-code&amp;gt; &amp;lt;reason-phrase&amp;gt;
&amp;lt;Response-Header&amp;gt;
&amp;lt;Representational-Header&amp;gt;
&amp;lt;Request-Body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;below is the real example of response Send by Server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 201 Created
Content-Type: application/json
Location: http://Arkaai.dev/users/123

{
  "message": "New user created",
  "user": {
    "id": 123,
    "firstName": "Rohit",
    "lastName": "Giri",
    "email": "rg123@ai.com"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Status-Code&lt;/strong&gt;&lt;br&gt;
It is very important to understand the Status-Code. Http has 5 types of Status code. These codes tell us the result of the request made by the client (browser/app) to the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.  1xx → Informational&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Meaning: Request received, processing continues&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Used rarely in real websites.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;100 Continue → Server says “ok, send the body”&lt;/li&gt;
&lt;li&gt;101 Switching Protocols → Upgrading protocol (like HTTP → WebSocket)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.  2xx → Success&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Meaning: Request successfully completed&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;200 OK → Request success &lt;/li&gt;
&lt;li&gt;201 Created → New resource created (mostly in POST)&lt;/li&gt;
&lt;li&gt;204 No Content → Success but no response body&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.  3xx → Redirection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Meaning: Client needs to take another action / moved&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;301 Moved Permanently → URL changed permanently&lt;/li&gt;
&lt;li&gt;302 Found / Temporary Redirect → temporarily moved&lt;/li&gt;
&lt;li&gt;304 Not Modified → use cache, no need to download again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. 4xx → Client Error&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Meaning: Problem from client side (wrong request, invalid URL, etc.)&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;400 Bad Request → wrong format / invalid data&lt;/li&gt;
&lt;li&gt;401 Unauthorized → login required&lt;/li&gt;
&lt;li&gt;403 Forbidden → not allowed even after login&lt;/li&gt;
&lt;li&gt;404 Not Found → page/resource not found&lt;/li&gt;
&lt;li&gt;429 Too Many Requests → rate limit exceeded&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5.  5xx → Server Error&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Meaning: Server failed to process correct request&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;500 Internal Server Error → server crashed or bug&lt;/li&gt;
&lt;li&gt;502 Bad Gateway → server got invalid response from another server&lt;/li&gt;
&lt;li&gt;503 Service Unavailable → server down / overload&lt;/li&gt;
&lt;li&gt;504 Gateway Timeout → server didn’t respond in time&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Idempotent VS Non-Idempotent
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Idempotent&lt;/strong&gt; methods can be called multiple times with the same result.&lt;br&gt;
Examples (Idempotent methods):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET → only fetch data&lt;/li&gt;
&lt;li&gt;PUT → update/replace resource (same data again = same final state)&lt;/li&gt;
&lt;li&gt;DELETE → delete resource (deleting again won’t change more)&lt;/li&gt;
&lt;li&gt;HEAD / OPTIONS → metadata only&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Non-idempotent&lt;/strong&gt; methods that can produce different result on every call.&lt;br&gt;
Examples (Non-idempotent methods):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;POST → creates new resource every time&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Options method and CORS workflow
&lt;/h2&gt;

&lt;p&gt;OPTIONS Method: Used to fetch the capabilities of a server for a cross-origin request. Not directly used by developers but seen in browser network tabs as "pre-flight requests".&lt;br&gt;
Same-Origin Policy (SOP): Browsers restrict web pages from making requests to a domain different from their own.&lt;br&gt;
Cross-Origin Resource Sharing(CORS): A security mechanism enforced by browsers to control how web applications interact with resources on different domains.&lt;/p&gt;

&lt;p&gt;basically there are two types of request Simple Request and Pre-flighted Request&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Request Flow:&lt;/strong&gt;&lt;br&gt;
Used for methods like GET, POST, or HEAD.&lt;br&gt;
The client sends a request with an Origin header.&lt;br&gt;
The server checks the Origin header against its CORS policy and, if allowed, includes Access-Control-Allow-Origin in the response.&lt;br&gt;
If the header is absent or doesn't match, the browser blocks the response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-flight Request Flow:&lt;/strong&gt;&lt;br&gt;
Triggered when conditions like non-simple HTTP methods (e.g., PUT, DELETE), custom headers, or specific Content-Type values are used.&lt;br&gt;
The browser sends an OPTIONS request before the actual request. This inquiry asks the server if the intended method, headers, and origin are allowed.&lt;br&gt;
The server responds with Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, and Access-Control-Max-Age (to cache pre-flight results).&lt;br&gt;
If the pre-flight request is successful (status 204 No Content), the browser sends the original request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPTIONS /resource/foo
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: x-requested-with
Origin: https://arkaai.dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example Response of pre-flighted request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 204 No Content
Connection: keep-alive
Access-Control-Allow-Origin: https://arkaai.dev
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Access-Control-Allow-Headers: X-Requested-With
Access-Control-Max-Age: 86400
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  HTTP Caching
&lt;/h3&gt;

&lt;p&gt;Purpose: Stores copies of frequently accessed resources to reduce server load and improve performance.&lt;/p&gt;

&lt;p&gt;Mechanism: When a client requests a resource, the cache determines if it has a fresh copy. If so, it serves the cached version. If not, it fetches from the server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F595sqhyniej36eg64dda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F595sqhyniej36eg64dda.png" alt="Http Caching Mechanism" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cache Headers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cache-Control:&lt;/strong&gt; Primary header for controlling caching behavior (e.g., no-store, no-cache, max-age, public, private).&lt;br&gt;
&lt;strong&gt;Expires:&lt;/strong&gt; Provides an absolute expiration date/time.&lt;br&gt;
&lt;strong&gt;ETag:&lt;/strong&gt; Unique identifier for a resource's content. Used for conditional requests.&lt;br&gt;
&lt;strong&gt;Last-Modified:&lt;/strong&gt; Timestamp of when the resource was last modified.&lt;br&gt;
Conditional Requests: Clients send headers like If-None-Match (with ETag) or If-Modified-Since (with Last-Modified). If the resource hasn't changed, the server responds with 304 Not Modified, telling the client to use its cached version.&lt;/p&gt;
&lt;h3&gt;
  
  
  Persistent Connections and Keep-Alive
&lt;/h3&gt;

&lt;p&gt;Persistent Connections (HTTP 1.1+): Keep the TCP connection open after a request/response, allowing multiple requests to be sent over the same connection. This avoids the overhead of establishing a new connection for each request.&lt;br&gt;
Connection: keep-alive Header: Instructs the server to keep the connection open.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 11 jan 2026 15:23:13 GMT
Keep-Alive: timeout=5, max=200
Last-Modified: Mon, 10 jan 2026 04:32:39 GMT
Server: Apache

(body)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;HTTP is not just “a protocol that transfers hypertext” — it’s the core communication language of the web. Every time we open a website, log in, stream content, or call an API, HTTP quietly manages the conversation between the client and the server.&lt;/p&gt;

&lt;p&gt;In this article, we didn’t look at HTTP as a textbook definition — we broke it down from the ground up: how computers communicate using IP addresses, how the client-server model works, how HTTP requests and responses are structured, and why status codes are essential for debugging.&lt;/p&gt;

&lt;p&gt;We also explored how HTTP evolved from HTTP/1.0 to HTTP/3, and why features like persistent connections, multiplexing, QUIC, and caching matter for performance. Concepts like idempotency help us design safer APIs, and workflows like CORS + preflight requests explain why browsers behave differently than tools like Postman.&lt;/p&gt;

&lt;p&gt;Once you understand HTTP deeply, you don’t just use the internet — you understand what’s happening behind it.&lt;/p&gt;

&lt;p&gt;And that’s what turns a normal developer into someone who can build, debug, and scale real-world applications confidently. 🚀🔥&lt;/p&gt;

</description>
      <category>backend</category>
      <category>beginners</category>
      <category>networking</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
