<?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>Forem: keshav Sandhu</title>
    <description>The latest articles on Forem by keshav Sandhu (@keshav___dev).</description>
    <link>https://forem.com/keshav___dev</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2066492%2F9d1e5d81-c9c1-491c-bc1f-52fe97284357.png</url>
      <title>Forem: keshav Sandhu</title>
      <link>https://forem.com/keshav___dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/keshav___dev"/>
    <language>en</language>
    <item>
      <title>🚀 JavaScript Async/Await vs `.then()` : The Microtask &amp; Event Loop Secret</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Wed, 18 Mar 2026 17:09:24 +0000</pubDate>
      <link>https://forem.com/keshav___dev/javascript-asyncawait-vs-then-the-microtask-event-loop-secret-2e8n</link>
      <guid>https://forem.com/keshav___dev/javascript-asyncawait-vs-then-the-microtask-event-loop-secret-2e8n</guid>
      <description>&lt;p&gt;Ever seen this and wondered why the output changes just by reordering lines?&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="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hi&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;there&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="c1"&gt;// Version A&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;waitedhi&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;hi&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="nx"&gt;waitedhi&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&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="nx"&gt;res&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="s2"&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;vs&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;// Version B&lt;/span&gt;
&lt;span class="nf"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&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="nx"&gt;res&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;waitedhi&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;hi&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="nx"&gt;waitedhi&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="s2"&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;👀 Same code… different output. Why?&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 The Hidden Mechanism: Microtasks
&lt;/h2&gt;

&lt;p&gt;Both &lt;code&gt;await&lt;/code&gt; and &lt;code&gt;.then()&lt;/code&gt; use &lt;strong&gt;Promises&lt;/strong&gt;, and both schedule work in the &lt;strong&gt;microtask queue&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;👉 Key rule:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Microtasks run in the order they are added (FIFO)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ⚡ What &lt;code&gt;await&lt;/code&gt; really does
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is roughly:&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="nf"&gt;hi&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// rest of your code&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.then()&lt;/code&gt; → schedules a microtask&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;await&lt;/code&gt; → schedules a microtask (continuation)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔥 Why order matters
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Version A
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;await&lt;/code&gt; schedules continuation&lt;/li&gt;
&lt;li&gt;resumes → logs &lt;code&gt;"there"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.then()&lt;/code&gt; schedules another microtask&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"end"&lt;/code&gt; logs&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.then()&lt;/code&gt; runs&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;there
end
there
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Version B
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;.then()&lt;/code&gt; → microtask A&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;await&lt;/code&gt; → microtask B&lt;/li&gt;
&lt;li&gt;Run A → Run B&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;there
there
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧩 The Bigger Picture: Event Loop
&lt;/h2&gt;

&lt;p&gt;To fully understand this, you need &lt;strong&gt;3 things&lt;/strong&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  1️⃣ Call Stack
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Executes synchronous code&lt;/li&gt;
&lt;li&gt;Runs &lt;strong&gt;line by line&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="s2"&gt;start&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;h3&gt;
  
  
  2️⃣ Microtask Queue (High Priority)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Promises (&lt;code&gt;.then&lt;/code&gt;, &lt;code&gt;await&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Runs &lt;strong&gt;immediately after stack is empty&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3️⃣ Macrotask Queue (Low Priority)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;setTimeout&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;setInterval&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Runs &lt;strong&gt;after all microtasks are done&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚡ Golden Rule
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;JS finishes the call stack → runs ALL microtasks → then runs ONE macrotask&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧪 Full Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;setTimeout&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;timeout&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;then&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&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="s2"&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;h3&gt;
  
  
  🔍 Execution Flow
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Call Stack&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Queues&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;Microtasks: [then, await-resume]
Macrotasks: [timeout]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Run Microtasks&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;then
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Run Macrotask&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;timeout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ Final Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;start
then
end
timeout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎯 Final Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;await&lt;/code&gt; = pause + schedule continuation as &lt;strong&gt;microtask&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.then()&lt;/code&gt; = directly schedules &lt;strong&gt;microtask&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Microtasks always run &lt;strong&gt;before macrotasks&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Order of scheduling = order of execution&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;💬 Once you understand this, async JavaScript stops feeling random and starts feeling predictable.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>MongoDB vs PostgreSQL: When to Choose Which One? (With Real-World Examples)</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Thu, 22 Jan 2026 16:59:15 +0000</pubDate>
      <link>https://forem.com/keshav___dev/mongodb-vs-postgresql-when-to-choose-which-one-with-real-world-examples-l56</link>
      <guid>https://forem.com/keshav___dev/mongodb-vs-postgresql-when-to-choose-which-one-with-real-world-examples-l56</guid>
      <description>&lt;p&gt;Choosing the right database is one of the most important architectural decisions you'll make in a project. Pick the wrong one, and you’ll fight with schema migrations, performance bottlenecks, or scalability issues down the road. Pick the right one, and your development speed, data consistency, and long-term maintenance will thank you.&lt;/p&gt;

&lt;p&gt;Two of the most popular options today are &lt;strong&gt;MongoDB&lt;/strong&gt; (NoSQL, document-oriented) and &lt;strong&gt;PostgreSQL&lt;/strong&gt; (relational, SQL). They solve different problems well, and the “best” choice almost always depends on your data model, query patterns, and scalability needs.&lt;/p&gt;

&lt;p&gt;In this post, we’ll break down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core strengths and trade-offs of each&lt;/li&gt;
&lt;li&gt;Clear guidelines on when to choose one over the other&lt;/li&gt;
&lt;li&gt;Real-world projects that use each (including an admin-panel example)&lt;/li&gt;
&lt;li&gt;A side-by-side comparison to help you decide quickly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s dive in.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. MongoDB: Flexible, Schema-less, Horizontally Scalable
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What MongoDB Is Great For
&lt;/h3&gt;

&lt;p&gt;MongoDB stores data as &lt;strong&gt;JSON-like BSON documents&lt;/strong&gt; in collections. There’s no fixed schema - you can add new fields anytime without migrations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key strengths&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rapid development when requirements evolve quickly&lt;/li&gt;
&lt;li&gt;Handling unstructured or semi-structured data (e.g., user profiles with optional fields, logs, IoT sensor data)&lt;/li&gt;
&lt;li&gt;High write throughput and horizontal scaling via sharding&lt;/li&gt;
&lt;li&gt;Nested data models that reduce the need for JOINs&lt;/li&gt;
&lt;li&gt;Built-in replication and auto-sharding for distributed systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trade-offs&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Weaker ACID guarantees by default (though multi-document transactions exist, they’re slower)&lt;/li&gt;
&lt;li&gt;Complex queries with many joins are harder and less efficient&lt;/li&gt;
&lt;li&gt;Eventual consistency in distributed setups can bite you if you need strict consistency&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Choose MongoDB
&lt;/h3&gt;

&lt;p&gt;Choose MongoDB when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your data structure changes frequently&lt;/li&gt;
&lt;li&gt;You have high-velocity writes (real-time analytics, event streaming)&lt;/li&gt;
&lt;li&gt;You need to scale horizontally across many servers easily&lt;/li&gt;
&lt;li&gt;You’re working with hierarchical or variable data (e.g., product catalogs with different attributes per category)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real-World MongoDB Projects
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Aadhaar (India’s National ID System)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The world’s largest biometric database, storing records for over 1.3 billion people. MongoDB handles massive volumes of semi-structured biometric and demographic data. Its flexible schema allows quick updates as new data types (fingerprints, iris scans) are added, and sharding supports enormous scale across distributed enrollment centers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Wells Fargo Payment Processing&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Processes millions of card transactions daily. MongoDB’s document model easily accommodates varying transaction metadata, and its horizontal scaling ensures low-latency fraud detection and real-time settlement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Novo Nordisk Clinical Trials Platform&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Uses MongoDB Atlas to store and analyze unstructured clinical study data. Researchers can evolve data models as trials progress, and generative AI tools query the flexible documents to produce reports in minutes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. PostgreSQL: Powerful, Relational, ACID-Compliant
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What PostgreSQL Is Great For
&lt;/h3&gt;

&lt;p&gt;PostgreSQL is a battle-tested relational database with full SQL support, rich data types, and extensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key strengths&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strong ACID compliance and transactional integrity&lt;/li&gt;
&lt;li&gt;Complex queries with JOINs, aggregations, window functions&lt;/li&gt;
&lt;li&gt;Advanced features: JSONB (best-of-both-worlds semi-structured data), full-text search, PostGIS for geospatial, custom extensions&lt;/li&gt;
&lt;li&gt;Data consistency with constraints, foreign keys, triggers&lt;/li&gt;
&lt;li&gt;Excellent for analytical workloads and reporting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trade-offs&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Schema changes require migrations (can slow iteration in early stages)&lt;/li&gt;
&lt;li&gt;Vertical scaling is primary; horizontal scaling requires extra tools (Citus, sharding)&lt;/li&gt;
&lt;li&gt;Higher overhead for very high-write, unstructured workloads&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Choose PostgreSQL
&lt;/h3&gt;

&lt;p&gt;Choose PostgreSQL when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have structured data with clear relationships&lt;/li&gt;
&lt;li&gt;You need complex queries, reporting, or analytics&lt;/li&gt;
&lt;li&gt;Data integrity and consistency are non-negotiable (finance, inventory, user management)&lt;/li&gt;
&lt;li&gt;You want to mix relational and semi-structured data (thanks to JSONB)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real-World PostgreSQL Projects
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reddit’s Core Data and Analytics&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Reddit uses PostgreSQL for storing posts, comments, votes, users, and subreddits. The relational model handles complex relationships (e.g., comment threads, moderation actions) and ensures transactional consistency during high-traffic voting spikes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;NASA International Space Station Monitoring&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Telemetry and event data from the ISS are stored in PostgreSQL for ground replication. ACID guarantees prevent data loss, and reliable replication supports mission-critical real-time monitoring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Library Management System Admin Panel (Common Full-Stack Example)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Many real-world admin dashboards (library systems, school management, e-commerce backends) use PostgreSQL.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tables: &lt;code&gt;users&lt;/code&gt;, &lt;code&gt;books&lt;/code&gt;, &lt;code&gt;authors&lt;/code&gt;, &lt;code&gt;borrow_records&lt;/code&gt;, &lt;code&gt;fines&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Relationships: A book has one author (foreign key), a user can have many borrow records
&lt;/li&gt;
&lt;li&gt;Typical admin-panel features:

&lt;ul&gt;
&lt;li&gt;Search/overdue reports using JOINs and aggregations
&lt;/li&gt;
&lt;li&gt;Atomic borrow/return transactions (update inventory and create record in one transaction)
&lt;/li&gt;
&lt;li&gt;Role-based access with consistent user data
PostgreSQL shines here because the data is highly relational, queries are complex (e.g., “top 10 most borrowed books this month”), and consistency matters (you can’t have a borrow record without updating book availability).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Side-by-Side Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;MongoDB&lt;/th&gt;
&lt;th&gt;PostgreSQL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Data Model&lt;/td&gt;
&lt;td&gt;Document (flexible schema)&lt;/td&gt;
&lt;td&gt;Relational (fixed schema)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query Language&lt;/td&gt;
&lt;td&gt;MongoDB Query Language / Aggregation&lt;/td&gt;
&lt;td&gt;SQL (rich, standardized)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scaling&lt;/td&gt;
&lt;td&gt;Horizontal (sharding built-in)&lt;/td&gt;
&lt;td&gt;Primarily vertical; horizontal via extensions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transactions&lt;/td&gt;
&lt;td&gt;Multi-document (slower)&lt;/td&gt;
&lt;td&gt;Full ACID, multi-statement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex Joins&lt;/td&gt;
&lt;td&gt;Difficult/inefficient&lt;/td&gt;
&lt;td&gt;Excellent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema Evolution&lt;/td&gt;
&lt;td&gt;Easy (schema-less)&lt;/td&gt;
&lt;td&gt;Requires migrations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best Workloads&lt;/td&gt;
&lt;td&gt;High-write, evolving data&lt;/td&gt;
&lt;td&gt;Analytics, relationships, consistency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON/Semi-structured&lt;/td&gt;
&lt;td&gt;Native&lt;/td&gt;
&lt;td&gt;Excellent via JSONB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Key Takeaways &amp;amp; Decision Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start with data structure&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Highly relational with fixed fields → PostgreSQL
&lt;/li&gt;
&lt;li&gt;Variable/nested/unpredictable fields → MongoDB&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Think about queries&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lots of JOINs, aggregations, reporting → PostgreSQL
&lt;/li&gt;
&lt;li&gt;Mostly simple lookups or document retrieval → MongoDB&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Consider consistency needs&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Banking, inventory, admin actions → PostgreSQL
&lt;/li&gt;
&lt;li&gt;Logs, events, user-generated content → MongoDB&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Future scaling&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Predict massive horizontal growth early → MongoDB
&lt;/li&gt;
&lt;li&gt;Start simple and scale vertically first → PostgreSQL&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You don’t always have to choose one&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Many modern apps use &lt;strong&gt;polyglot persistence&lt;/strong&gt;: PostgreSQL for core transactional data and MongoDB for logs, analytics, or flexible user content.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The right database isn’t about which is “better” - it’s about which fits your problem today and tomorrow.&lt;/p&gt;

&lt;p&gt;What’s your go-to database and why? Drop your experiences (or war stories) in the comments! 🚀&lt;/p&gt;

</description>
      <category>programming</category>
      <category>mongodb</category>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>Dockerizing Node.js Microservices with Docker Compose</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Wed, 14 Jan 2026 16:57:43 +0000</pubDate>
      <link>https://forem.com/keshav___dev/dockerizing-nodejs-microservices-with-docker-compose-432j</link>
      <guid>https://forem.com/keshav___dev/dockerizing-nodejs-microservices-with-docker-compose-432j</guid>
      <description>&lt;p&gt;If you’re working with &lt;strong&gt;Node.js microservices&lt;/strong&gt; and still running everything manually on your machine - this post is for you.&lt;/p&gt;

&lt;p&gt;In this guide, we’ll &lt;strong&gt;Dockerize multiple backend microservices&lt;/strong&gt; and run them together using &lt;strong&gt;Docker Compose&lt;/strong&gt;, the same way it’s done in real-world projects.&lt;/p&gt;

&lt;p&gt;No frontend. No fluff. Just &lt;strong&gt;clean backend architecture&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Docker for Microservices?
&lt;/h2&gt;

&lt;p&gt;Microservices mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple Node.js apps&lt;/li&gt;
&lt;li&gt;Different ports&lt;/li&gt;
&lt;li&gt;Shared infrastructure (DB, cache, queues)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without Docker:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Works on my machine” issues&lt;/li&gt;
&lt;li&gt;Manual setup every time&lt;/li&gt;
&lt;li&gt;Painful onboarding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With Docker:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Same environment everywhere&lt;/li&gt;
&lt;li&gt;One command to start everything&lt;/li&gt;
&lt;li&gt;Easy scaling &amp;amp; CI/CD&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What We’ll Build
&lt;/h2&gt;

&lt;p&gt;Backend-only setup with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;auth-service&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;user-service&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;order-service&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;li&gt;Docker + Docker Compose&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each service:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runs in its own container&lt;/li&gt;
&lt;li&gt;Has its own Dockerfile&lt;/li&gt;
&lt;li&gt;Communicates over Docker network&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;backend/
│
├── auth-service/
│   ├── Dockerfile
│   ├── package.json
│   ├── server.js
│   └── .dockerignore
│
├── user-service/
│   ├── Dockerfile
│   ├── package.json
│   ├── server.js
│   └── .dockerignore
│
├── order-service/
│   ├── Dockerfile
│   ├── package.json
│   ├── server.js
│   └── .dockerignore
│
├── docker-compose.yml
└── .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Common Dockerfile (Node.js Service)
&lt;/h2&gt;

&lt;p&gt;Each service uses the &lt;strong&gt;same Dockerfile pattern&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; node:18-alpine&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package*.json ./&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--production&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 5000&lt;/span&gt;

&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["npm", "start"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;.dockerignore&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules
.env
npm-debug.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps images small and clean.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sample Service Code
&lt;/h2&gt;

&lt;p&gt;Example: &lt;code&gt;auth-service/server.js&lt;/code&gt;&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;express&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="s2"&gt;express&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;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&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="s2"&gt;/health&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;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="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="na"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auth&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ok&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&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="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="s2"&gt;Auth service running on port 5000&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each microservice exposes a &lt;code&gt;/health&lt;/code&gt; endpoint — a &lt;strong&gt;best practice&lt;/strong&gt; for containers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Docker Compose (Multiple Microservices)
&lt;/h2&gt;

&lt;p&gt;This is where the magic happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.9"&lt;/span&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;auth-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./auth-service&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5001:5000"&lt;/span&gt;
    &lt;span class="na"&gt;env_file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;.env&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;mongo&lt;/span&gt;

  &lt;span class="na"&gt;user-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./user-service&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5002:5000"&lt;/span&gt;
    &lt;span class="na"&gt;env_file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;.env&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;mongo&lt;/span&gt;

  &lt;span class="na"&gt;order-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./order-service&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5003:5000"&lt;/span&gt;
    &lt;span class="na"&gt;env_file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;.env&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;mongo&lt;/span&gt;

  &lt;span class="na"&gt;mongo&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mongo:6&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;27017:27017"&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;mongo_data:/data/db&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;mongo_data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Environment Variables
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MONGO_URI=mongodb://mongo:27017/microservices_db
JWT_SECRET=supersecret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 &lt;strong&gt;Important Docker Rule&lt;/strong&gt;&lt;br&gt;
Inside Docker:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ &lt;code&gt;localhost&lt;/code&gt; does NOT work&lt;/li&gt;
&lt;li&gt;✅ Use service names (&lt;code&gt;mongo&lt;/code&gt;, &lt;code&gt;user-service&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Inter-Service Communication
&lt;/h2&gt;

&lt;p&gt;Inside containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auth-service → http://user-service:5000
user-service → http://order-service:5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&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="nx"&gt;axios&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="s2"&gt;http://user-service:5000/health&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;Docker automatically creates a &lt;strong&gt;shared network&lt;/strong&gt; for services in &lt;code&gt;docker-compose.yml&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Run Everything
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up &lt;span class="nt"&gt;--build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test locally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://localhost:5001/health" rel="noopener noreferrer"&gt;http://localhost:5001/health&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://localhost:5002/health" rel="noopener noreferrer"&gt;http://localhost:5002/health&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://localhost:5003/health" rel="noopener noreferrer"&gt;http://localhost:5003/health&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Production-Ready Tips
&lt;/h2&gt;

&lt;p&gt;✔ Give each service its &lt;strong&gt;own database&lt;/strong&gt;&lt;br&gt;
✔ Don’t expose ports for internal services&lt;br&gt;
✔ Add health checks&lt;br&gt;
✔ Use an &lt;strong&gt;API Gateway&lt;/strong&gt; (NGINX / Kong)&lt;br&gt;
✔ Move to &lt;strong&gt;Kubernetes&lt;/strong&gt; when scaling&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Each microservice runs in its own Docker container, communicates via Docker’s internal network using service names, and is orchestrated with Docker Compose.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you understand this setup, you’re already &lt;strong&gt;ahead of many backend devs&lt;/strong&gt;.&lt;/p&gt;




&lt;p&gt;If you found this useful, &lt;strong&gt;drop a ❤️ or comment&lt;/strong&gt; - happy to write a follow-up!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>microservices</category>
      <category>node</category>
    </item>
    <item>
      <title>MongoDB aggregation Pipelines simplified</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Mon, 27 Oct 2025 16:48:40 +0000</pubDate>
      <link>https://forem.com/keshav___dev/mongodb-aggregation-pipelines-simplified-53mp</link>
      <guid>https://forem.com/keshav___dev/mongodb-aggregation-pipelines-simplified-53mp</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;MongoDB Aggregation Pipeline stages&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MongoDB’s &lt;strong&gt;aggregation pipeline&lt;/strong&gt; is a powerful framework for transforming, filtering, and analyzing data in collections similar to SQL’s &lt;code&gt;GROUP BY&lt;/code&gt;, &lt;code&gt;JOIN&lt;/code&gt;, &lt;code&gt;WHERE&lt;/code&gt;, etc.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 Basic Structure
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;aggregation pipeline&lt;/strong&gt; is an array of &lt;strong&gt;stages&lt;/strong&gt;, each stage transforms the documents and passes them to the next stage.&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="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;stage1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;stage2&lt;/span&gt;&lt;span class="o"&gt;&amp;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  1️⃣ &lt;code&gt;$match&lt;/code&gt; - Filtering Documents
&lt;/h2&gt;

&lt;p&gt;Works like the &lt;code&gt;find()&lt;/code&gt; query. Filters documents based on conditions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;delivered&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="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Returns only documents where &lt;code&gt;status&lt;/code&gt; = &lt;code&gt;"delivered"&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2️⃣ &lt;code&gt;$project&lt;/code&gt; - Select or Reshape Fields
&lt;/h2&gt;

&lt;p&gt;Used to &lt;strong&gt;include/exclude fields&lt;/strong&gt; or &lt;strong&gt;create computed fields&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="na"&gt;$project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
      &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$multiply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$price&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="s2"&gt;$quantity&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="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Outputs only &lt;code&gt;item&lt;/code&gt; and a computed field &lt;code&gt;total&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  3️⃣ &lt;code&gt;$group&lt;/code&gt; - Group Documents &amp;amp; Aggregate Data
&lt;/h2&gt;

&lt;p&gt;Groups documents by a key and applies aggregation operators (like &lt;code&gt;$sum&lt;/code&gt;, &lt;code&gt;$avg&lt;/code&gt;, etc.).&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$customerId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;totalSpent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$multiply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$price&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="s2"&gt;$quantity&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="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;numOrders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&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="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Groups by customer and calculates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Total spent&lt;/li&gt;
&lt;li&gt;Number of orders&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4️⃣ &lt;code&gt;$sort&lt;/code&gt; - Sort Results
&lt;/h2&gt;

&lt;p&gt;Sorts documents by one or more fields.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c1"&gt;// descending&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Sorts by &lt;code&gt;total&lt;/code&gt; in descending order.&lt;/p&gt;




&lt;h2&gt;
  
  
  5️⃣ &lt;code&gt;$limit&lt;/code&gt; and &lt;code&gt;$skip&lt;/code&gt; - Pagination
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$limit&lt;/code&gt;: Restricts the number of documents.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$skip&lt;/code&gt;: Skips a number of documents.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&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="na"&gt;$skip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Skips first 10, returns next 5 (useful for pagination).&lt;/p&gt;




&lt;h2&gt;
  
  
  6️⃣ &lt;code&gt;$unwind&lt;/code&gt; - Deconstruct Arrays
&lt;/h2&gt;

&lt;p&gt;Splits array fields into multiple documents (one per element).&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$unwind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$items&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ If a document has an array &lt;code&gt;items: [a, b, c]&lt;/code&gt;, it becomes &lt;strong&gt;3 documents&lt;/strong&gt; - one for each item.&lt;/p&gt;




&lt;h2&gt;
  
  
  7️⃣ &lt;code&gt;$lookup&lt;/code&gt; - Join with Another Collection
&lt;/h2&gt;

&lt;p&gt;Performs a &lt;strong&gt;left outer join&lt;/strong&gt; between two collections.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$lookup&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;localField&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customerId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;foreignField&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;as&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customer&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="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Adds matching customer info to each order under the field &lt;code&gt;customer&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  8️⃣ &lt;code&gt;$addFields&lt;/code&gt; - Add or Modify Fields
&lt;/h2&gt;

&lt;p&gt;Adds new fields or modifies existing ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$addFields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$multiply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$price&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="s2"&gt;$quantity&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="na"&gt;statusUpper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$toUpper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$status&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Adds computed &lt;code&gt;total&lt;/code&gt; and uppercase &lt;code&gt;status&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  9️⃣ &lt;code&gt;$count&lt;/code&gt; - Count Documents
&lt;/h2&gt;

&lt;p&gt;Counts the number of documents in the pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pending&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pendingOrders&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Returns &lt;code&gt;{ pendingOrders: 12 }&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔟 &lt;code&gt;$facet&lt;/code&gt; - Multiple Pipelines in One
&lt;/h2&gt;

&lt;p&gt;Allows &lt;strong&gt;parallel aggregations&lt;/strong&gt; on the same dataset.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$facet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;totalByCustomer&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="na"&gt;$group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$customerId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$amount&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="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;avgOrderValue&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="na"&gt;$group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;avg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$avg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$amount&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="p"&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="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Runs two aggregations in one pipeline.&lt;/p&gt;




&lt;h2&gt;
  
  
  1️⃣1️⃣ &lt;code&gt;$bucket&lt;/code&gt; - Categorize Into Ranges
&lt;/h2&gt;

&lt;p&gt;Groups values into defined &lt;strong&gt;ranges (buckets)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$bucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;groupBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$amount&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;boundaries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Other&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Categorizes sales by amount ranges.&lt;/p&gt;




&lt;h2&gt;
  
  
  1️⃣2️⃣ &lt;code&gt;$out&lt;/code&gt; - Write Results to a Collection
&lt;/h2&gt;

&lt;p&gt;Saves aggregation results into a new collection.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;completed&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$out&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;completedOrders&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Writes output into a new collection &lt;code&gt;completedOrders&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1️⃣3️⃣ &lt;code&gt;$merge&lt;/code&gt; - Merge Results into an Existing Collection
&lt;/h2&gt;

&lt;p&gt;Similar to &lt;code&gt;$out&lt;/code&gt;, but can &lt;strong&gt;update or insert&lt;/strong&gt; documents.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$customerId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$amount&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="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$merge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;into&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customerTotals&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;whenMatched&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;merge&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;whenNotMatched&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insert&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="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Updates or inserts aggregated data into &lt;code&gt;customerTotals&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let me know if this helped you in some way. &lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>sql</category>
      <category>database</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Converting any JS project to TS backend</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Thu, 16 Oct 2025 12:55:04 +0000</pubDate>
      <link>https://forem.com/keshav___dev/converting-any-js-project-to-ts-backend-4m2l</link>
      <guid>https://forem.com/keshav___dev/converting-any-js-project-to-ts-backend-4m2l</guid>
      <description>&lt;p&gt;First step if you are setting up from scratch&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ 1. &lt;em&gt;Initialize Your Node.js Project&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
npm init -y&lt;/p&gt;

&lt;p&gt;Creates a package.json file.&lt;/p&gt;




&lt;p&gt;Conversion start now&lt;/p&gt;

&lt;h2&gt;
  
  
  ✅ 2. &lt;em&gt;Install TypeScript and Types for Node&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
npm install --save-dev typescript @types/node&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;typescript: the TypeScript compiler&lt;/li&gt;
&lt;li&gt;@types/node: type definitions for Node.js (so fs, path, etc. work)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ 3. &lt;em&gt;Initialize TypeScript Config&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
npx tsc --init&lt;/p&gt;

&lt;p&gt;This generates a tsconfig.json. You can use the default, but you might want to tweak a few settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommended tsconfig.json tweaks:
&lt;/h3&gt;

&lt;p&gt;jsonc&lt;br&gt;
{&lt;br&gt;
  "compilerOptions": {&lt;br&gt;
    "target": "es2020",&lt;br&gt;
    "module": "commonjs",&lt;br&gt;
    "outDir": "./dist",&lt;br&gt;
    "rootDir": "./src",&lt;br&gt;
    "strict": true,&lt;br&gt;
    "esModuleInterop": true,&lt;br&gt;
    "skipLibCheck": true&lt;br&gt;
  },&lt;br&gt;
  "include": ["src"]&lt;br&gt;
}&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ 4. &lt;em&gt;Create Your Project Structure&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
mkdir src&lt;br&gt;
touch src/index.ts&lt;/p&gt;

&lt;p&gt;Add a simple example in src/index.ts:&lt;/p&gt;

&lt;p&gt;ts&lt;br&gt;
const greet = (name: string) =&amp;gt; {&lt;br&gt;
  console.log(&lt;code&gt;Hello, ${name}!&lt;/code&gt;);&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;greet("TypeScript");&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ 5. &lt;em&gt;Compile TypeScript&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
npx tsc&lt;/p&gt;

&lt;p&gt;This compiles your TypeScript to JavaScript in the dist folder.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ 6. &lt;em&gt;Run the Compiled JavaScript&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
node dist/index.js&lt;/p&gt;




&lt;h2&gt;
  
  
  🔁 Optional: Add NPM Scripts
&lt;/h2&gt;

&lt;p&gt;Edit package.json to make your workflow easier:&lt;/p&gt;

&lt;p&gt;json&lt;br&gt;
"scripts": {&lt;br&gt;
  "build": "tsc",&lt;br&gt;
  "start": "node dist/index.js",&lt;br&gt;
  "dev": "tsc --watch"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Now you can run:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
npm run build   # Compile&lt;br&gt;
npm start       # Run&lt;br&gt;
npm run dev     # Watch and recompile on changes&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Optional: Use ts-node to Run TS Directly (without compiling)
&lt;/h2&gt;

&lt;p&gt;Install it:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
npm install --save-dev ts-node&lt;/p&gt;

&lt;p&gt;Run TypeScript directly:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
npx ts-node src/index.ts&lt;/p&gt;




</description>
      <category>programming</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript Object References – Explained with Examples</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Tue, 07 Oct 2025 17:09:56 +0000</pubDate>
      <link>https://forem.com/keshav___dev/javascript-object-references-explained-with-examples-nnm</link>
      <guid>https://forem.com/keshav___dev/javascript-object-references-explained-with-examples-nnm</guid>
      <description>&lt;p&gt;Lets start&lt;/p&gt;

&lt;h2&gt;
  
  
  🔹 1. &lt;em&gt;Objects Are Passed by Reference&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;In JavaScript, &lt;em&gt;objects (including arrays and functions)&lt;/em&gt; are assigned and passed &lt;em&gt;by reference&lt;/em&gt;, not by value.&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
const a = { name: "Alice" };&lt;br&gt;
const b = a;&lt;/p&gt;

&lt;p&gt;b.name = "Bob";&lt;/p&gt;

&lt;p&gt;console.log(a.name); // ➜ "Bob"&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✅ a and b both point to the &lt;em&gt;same object in memory&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 2. &lt;em&gt;Primitive Values Are Passed by Value&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
let x = 10;&lt;br&gt;
let y = x;&lt;/p&gt;

&lt;p&gt;y++;&lt;/p&gt;

&lt;p&gt;console.log(x); // 10&lt;br&gt;
console.log(y); // 11&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✅ x and y are completely separate.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 3. &lt;em&gt;Object Comparison Checks Reference, Not Structure&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
const obj1 = { a: 1 };&lt;br&gt;
const obj2 = { a: 1 };&lt;/p&gt;

&lt;p&gt;console.log(obj1 === obj2); // false&lt;/p&gt;

&lt;p&gt;Even though they look identical, they're two different objects in memory.&lt;/p&gt;

&lt;p&gt;✅ To compare deeply:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
JSON.stringify(obj1) === JSON.stringify(obj2); // true&lt;/p&gt;

&lt;p&gt;Or use a deep equality library like lodash.isEqual.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 4. &lt;em&gt;Mutating vs Copying Objects&lt;/em&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ❌ Mutating Original:
&lt;/h3&gt;

&lt;p&gt;js&lt;br&gt;
const user = { name: "Alice" };&lt;br&gt;
function update(user) {&lt;br&gt;
  user.name = "Bob";&lt;br&gt;
}&lt;br&gt;
update(user);&lt;br&gt;
console.log(user.name); // Bob&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Copying (Shallow):
&lt;/h3&gt;

&lt;p&gt;js&lt;br&gt;
const original = { a: 1 };&lt;br&gt;
const copy = { ...original };&lt;/p&gt;

&lt;p&gt;copy.a = 2;&lt;/p&gt;

&lt;p&gt;console.log(original.a); // 1&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;... or Object.assign() creates a &lt;em&gt;shallow copy&lt;/em&gt; - only top-level is copied.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 5. &lt;em&gt;Shallow vs Deep Copy&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
const obj = { a: 1, b: { c: 2 } };&lt;/p&gt;

&lt;p&gt;const shallowCopy = { ...obj };&lt;br&gt;
shallowCopy.b.c = 99;&lt;/p&gt;

&lt;p&gt;console.log(obj.b.c); // 99 ❌ (still affected!)&lt;/p&gt;

&lt;p&gt;✅ Deep Copy (one way):&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
const deepCopy = JSON.parse(JSON.stringify(obj));&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This has limitations (won’t work with functions, Dates, undefined, circular refs).&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 6. &lt;em&gt;Object Mutation in Arrays&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
const users = [{ name: "Alice" }];&lt;br&gt;
const newUsers = users;&lt;/p&gt;

&lt;p&gt;newUsers[0].name = "Bob";&lt;/p&gt;

&lt;p&gt;console.log(users[0].name); // "Bob" ❗&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;users and newUsers point to the same array and same object inside it.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 7. &lt;em&gt;Object Identity in State (React relevance)&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;In React:&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
const [state, setState] = useState({ count: 0 });&lt;/p&gt;

&lt;p&gt;setState({ count: 0 }); // Will re-render (new object reference)&lt;/p&gt;

&lt;p&gt;React &lt;em&gt;compares by reference&lt;/em&gt;, not deep equality.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Even if content is same, new object → re-render ✅&lt;br&gt;
But if reference is same, no re-render (optimization)&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 8. &lt;em&gt;Freezing an Object (Make it Immutable)&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
const obj = Object.freeze({ a: 1 });&lt;br&gt;
obj.a = 99; // ❌ won't change&lt;/p&gt;

&lt;p&gt;console.log(obj.a); // 1&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Works only on top-level (not deeply)&lt;/li&gt;
&lt;li&gt;Good for read-only configs&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 9. &lt;em&gt;References Inside Functions&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
function mutate(obj) {&lt;br&gt;
  obj.changed = true;&lt;br&gt;
}&lt;br&gt;
const data = {};&lt;br&gt;
mutate(data);&lt;/p&gt;

&lt;p&gt;console.log(data.changed); // true&lt;/p&gt;

&lt;p&gt;✅ Passing an object to a function allows &lt;em&gt;mutating it from inside&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 10. &lt;em&gt;Comparing Arrays and Functions by Reference&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;js&lt;br&gt;
const a = [1, 2];&lt;br&gt;
const b = [1, 2];&lt;br&gt;
console.log(a === b); // false&lt;/p&gt;

&lt;p&gt;const f1 = () =&amp;gt; {};&lt;br&gt;
const f2 = () =&amp;gt; {};&lt;br&gt;
console.log(f1 === f2); // false&lt;/p&gt;

&lt;p&gt;Even if they look identical, they are &lt;em&gt;different objects/functions&lt;/em&gt; in memory.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Summary – Key Concepts
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Reference Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Objects&lt;/td&gt;
&lt;td&gt;Reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arrays&lt;/td&gt;
&lt;td&gt;Reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Functions&lt;/td&gt;
&lt;td&gt;Reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primitives (string, number)&lt;/td&gt;
&lt;td&gt;Value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comparison (===)&lt;/td&gt;
&lt;td&gt;Compares references&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spread/assign&lt;/td&gt;
&lt;td&gt;Shallow copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON methods&lt;/td&gt;
&lt;td&gt;Deep copy (with limits)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>open source</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Thu, 28 Aug 2025 17:07:58 +0000</pubDate>
      <link>https://forem.com/keshav___dev/-1a26</link>
      <guid>https://forem.com/keshav___dev/-1a26</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/keshav___dev" 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%2F2066492%2F9d1e5d81-c9c1-491c-bc1f-52fe97284357.png" alt="keshav___dev"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/keshav___dev/how-to-contribute-to-open-source-even-if-youre-just-starting-out-1n1d" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;🌍 How to Contribute to Open Source (Even If You're Just Starting Out)&lt;/h2&gt;
      &lt;h3&gt;keshav Sandhu ・ Aug 28&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#opensource&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#ai&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#agentaichallenge&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>opensource</category>
      <category>ai</category>
      <category>agentaichallenge</category>
      <category>programming</category>
    </item>
    <item>
      <title>🌍 How to Contribute to Open Source (Even If You're Just Starting Out)</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Thu, 28 Aug 2025 17:07:28 +0000</pubDate>
      <link>https://forem.com/keshav___dev/how-to-contribute-to-open-source-even-if-youre-just-starting-out-1n1d</link>
      <guid>https://forem.com/keshav___dev/how-to-contribute-to-open-source-even-if-youre-just-starting-out-1n1d</guid>
      <description>&lt;p&gt;Contributing to &lt;em&gt;open source&lt;/em&gt; can feel intimidating like you're walking into someone else’s codebase without an invitation. But the truth is: open source is one of the best ways to &lt;em&gt;level up your skills, build your **developer reputation&lt;/em&gt;, and give back to the community.&lt;/p&gt;

&lt;p&gt;Whether you're a beginner, student, or seasoned dev, this post breaks down exactly how to get started contributing to open source.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Why Contribute to Open Source?
&lt;/h2&gt;

&lt;p&gt;Here’s what you gain:&lt;/p&gt;

&lt;p&gt;✅ Real-world experience&lt;br&gt;
✅ Learn by reading (and writing) production-quality code&lt;br&gt;
✅ Improve collaboration, Git, and code review skills&lt;br&gt;
✅ Get visibility and build a strong portfolio&lt;br&gt;
✅ Make a real impact, your code could be used by thousands (or millions!)&lt;/p&gt;




&lt;h2&gt;
  
  
  🪜 Step-by-Step: How to Contribute to an Open Source Project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;em&gt;Set Expectations (Start Small)&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;You don’t have to dive into the Linux kernel or rewrite a compiler. Start with small, meaningful contributions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fixing typos or broken links in documentation&lt;/li&gt;
&lt;li&gt;Improving README files&lt;/li&gt;
&lt;li&gt;Filing or triaging issues&lt;/li&gt;
&lt;li&gt;Fixing bugs labeled &lt;em&gt;"good first issue"&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Writing tests or improving coverage&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. &lt;em&gt;Find a Project That Interests You&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;You’ll stay more motivated if the project relates to something you use or care about.&lt;/p&gt;

&lt;p&gt;🧭 Where to find beginner-friendly projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://goodfirstissue.dev/" rel="noopener noreferrer"&gt;Good First Issue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://up-for-grabs.net/" rel="noopener noreferrer"&gt;Up For Grabs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codetriage.com/" rel="noopener noreferrer"&gt;CodeTriage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;GitHub search with label:"good first issue" or label:"help wanted"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tools or libraries you already use (VS Code, React, Django, etc.)&lt;/li&gt;
&lt;li&gt;Awesome lists on GitHub like &lt;a href="https://github.com/MunGell/awesome-for-beginners" rel="noopener noreferrer"&gt;Awesome for Beginners&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. &lt;em&gt;Understand the Project&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Before writing a single line of code:&lt;/p&gt;

&lt;p&gt;✅ Read the &lt;em&gt;README&lt;/em&gt;&lt;br&gt;
✅ Check the &lt;em&gt;CONTRIBUTING.md&lt;/em&gt; file (rules + how-tos)&lt;br&gt;
✅ Browse open &lt;em&gt;issues&lt;/em&gt; and discussions&lt;br&gt;
✅ Look at the project’s &lt;em&gt;code structure&lt;/em&gt; and &lt;em&gt;commit history&lt;/em&gt;&lt;br&gt;
✅ Join the project's &lt;em&gt;Discord, Slack, or Gitter&lt;/em&gt;, if available&lt;/p&gt;

&lt;p&gt;Pro tip: Some projects even have a DEVELOPERS.md or docs/ folder to explain how things work.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. &lt;em&gt;Pick a First Issue (and Ask to Work on It)&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Find an issue labeled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;good first issue&lt;/li&gt;
&lt;li&gt;help wanted&lt;/li&gt;
&lt;li&gt;beginner friendly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Comment on it:&lt;/p&gt;

&lt;p&gt;Hi! I'd love to work on this issue. Is it still available?&lt;/p&gt;

&lt;p&gt;Wait for a maintainer to assign it to you or confirm it's open. Then you're good to go!&lt;/p&gt;




&lt;h3&gt;
  
  
  5. &lt;em&gt;Fork → Clone → Code&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Standard contribution flow:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Fork&lt;/em&gt; the repo to your GitHub account&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Clone&lt;/em&gt; it to your local machine&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;git clone &lt;a href="https://github.com/your-username/project-name" rel="noopener noreferrer"&gt;https://github.com/your-username/project-name&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;em&gt;feature branch&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;bash&lt;br&gt;
   git checkout -b fix-typo-in-readme&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make your changes and commit&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Push&lt;/em&gt; your branch and open a &lt;em&gt;Pull Request (PR)&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  6. &lt;em&gt;Write a Great Pull Request (PR)&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Your PR should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a clear title (Fix typo in README)&lt;/li&gt;
&lt;li&gt;Include a brief description of the change&lt;/li&gt;
&lt;li&gt;Reference the issue number (e.g., Closes #42)&lt;/li&gt;
&lt;li&gt;Pass tests and linters (run them locally if possible)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example PR description:&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Fixed a small typo in the README file under the installation section.&lt;/p&gt;

&lt;p&gt;Closes #42&lt;/p&gt;




&lt;h3&gt;
  
  
  7. &lt;em&gt;Be Open to Feedback&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Most maintainers are kind but they may request changes. That’s totally normal.&lt;/p&gt;

&lt;p&gt;✅ Respond politely&lt;br&gt;
✅ Ask questions if you’re unsure&lt;br&gt;
✅ Make revisions and push again&lt;/p&gt;

&lt;p&gt;Once approved, your code will be merged 🎉&lt;/p&gt;




&lt;h2&gt;
  
  
  🙌 Best Practices and Pro Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Stay consistent&lt;/em&gt; with the project's coding style&lt;/li&gt;
&lt;li&gt;Always &lt;em&gt;pull the latest main branch&lt;/em&gt; before starting new work&lt;/li&gt;
&lt;li&gt;Write &lt;em&gt;clear commit messages&lt;/em&gt; (fix: correct typo in command)&lt;/li&gt;
&lt;li&gt;Don’t take feedback personally, it’s part of learning&lt;/li&gt;
&lt;li&gt;Celebrate small wins!&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💬 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Open source isn’t about being perfect. It’s about collaborating and growing together.&lt;/p&gt;

&lt;p&gt;Start small. Contribute often. And remember: the first PR is the hardest after that, it gets easier (and addictive 😄).&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Resources to Help You Get Started
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://firstcontributions.github.io/" rel="noopener noreferrer"&gt;First Contributions&lt;/a&gt; – Practice open source contribution in a safe repo&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/get-started/quickstart/fork-a-repo" rel="noopener noreferrer"&gt;GitHub Docs – Forking Projects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guides.github.com/introduction/git-handbook/" rel="noopener noreferrer"&gt;Git Handbook by GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;👋 Have you contributed to open source before? Got tips or favorite beginner-friendly projects? Drop them in the comments and let’s help more devs get started.&lt;/p&gt;




</description>
      <category>opensource</category>
      <category>ai</category>
      <category>agentaichallenge</category>
      <category>programming</category>
    </item>
    <item>
      <title>🔥 Demystifying Scalability in Backend Systems (with Microservices in Mind)</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Sun, 24 Aug 2025 16:33:17 +0000</pubDate>
      <link>https://forem.com/keshav___dev/demystifying-scalability-in-backend-systems-with-microservices-in-mind-2gmb</link>
      <guid>https://forem.com/keshav___dev/demystifying-scalability-in-backend-systems-with-microservices-in-mind-2gmb</guid>
      <description>&lt;p&gt;In the world of backend architecture, one term you'll hear over and over again is &lt;strong&gt;scalability&lt;/strong&gt;. It’s not just a buzzword—it's the backbone of building software that survives real-world usage and growth.&lt;/p&gt;

&lt;p&gt;But what &lt;em&gt;is&lt;/em&gt; scalability? And how do &lt;strong&gt;microservices&lt;/strong&gt; help us scale smarter, not harder?&lt;/p&gt;

&lt;p&gt;Let’s break it down.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What Is Scalability?
&lt;/h2&gt;

&lt;p&gt;At its core, &lt;strong&gt;scalability&lt;/strong&gt; is a system’s ability to &lt;strong&gt;handle increased load gracefully&lt;/strong&gt; whether that load comes from more users, more data, or higher transaction rates.&lt;/p&gt;

&lt;p&gt;A scalable backend can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grow to meet demand without crashing or slowing down&lt;/li&gt;
&lt;li&gt;Shrink when demand drops to save costs&lt;/li&gt;
&lt;li&gt;Be updated and deployed without major downtime&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚙️ Two Types of Scalability
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Vertical Scaling&lt;/strong&gt; (Scaling Up)
&lt;/h3&gt;

&lt;p&gt;Upgrade your existing server by adding more CPU, RAM, or storage.&lt;/p&gt;

&lt;p&gt;✅ Simple to implement&lt;br&gt;
❌ Eventually hits hardware limits&lt;br&gt;
❌ More expensive per unit as you scale&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Horizontal Scaling&lt;/strong&gt; (Scaling Out)
&lt;/h3&gt;

&lt;p&gt;Add more machines (servers or containers) to distribute the load.&lt;/p&gt;

&lt;p&gt;✅ Highly scalable&lt;br&gt;
✅ Cost-effective at scale&lt;br&gt;
✅ Enables fault tolerance&lt;br&gt;
❌ Requires smarter architecture&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Why Microservices Make Scaling Easier
&lt;/h2&gt;

&lt;p&gt;Monolithic apps bundle all features in one codebase. If one feature (e.g., checkout) needs more resources, you have to scale the whole app—wasting compute and memory.&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;microservices&lt;/strong&gt;, you can isolate and scale &lt;strong&gt;only&lt;/strong&gt; the parts that are under pressure.&lt;/p&gt;




&lt;h3&gt;
  
  
  🛒 Example: E-commerce Platform on Sale Day
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Microservice&lt;/th&gt;
&lt;th&gt;Load Spike&lt;/th&gt;
&lt;th&gt;Scaling Strategy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🧑‍💼 User Service&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;No scaling needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🛍️ Product Service&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Add 5 more instances via container orchestration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;💳 Payment Service&lt;/td&gt;
&lt;td&gt;Very High&lt;/td&gt;
&lt;td&gt;Scale + add a queue (e.g., Kafka) to absorb spikes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📦 Shipping Service&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;Scale 2x horizontally&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With microservices, each component runs independently. You can deploy, scale, and monitor each service on its own.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ Tools That Make It Happen
&lt;/h2&gt;

&lt;p&gt;Here’s how teams scale microservices efficiently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Containers&lt;/strong&gt;: Docker lets you package services with everything they need to run&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Orchestration&lt;/strong&gt;: Kubernetes or ECS handles service scaling, networking, and availability&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancers&lt;/strong&gt;: NGINX, HAProxy, or cloud-based balancers spread traffic across instances&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Queues&lt;/strong&gt;: Kafka, RabbitMQ, and AWS SQS prevent bottlenecks and enable async processing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CDNs + Caching&lt;/strong&gt;: Redis, Memcached, or Cloudflare reduce pressure on services&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📈 Scalability in Practice
&lt;/h2&gt;

&lt;p&gt;Scalability isn’t just about handling a one-time surge, it's about being ready for &lt;strong&gt;growth, volatility, and resilience&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It lets your system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle millions of users without rewriting everything&lt;/li&gt;
&lt;li&gt;Deploy updates with zero downtime&lt;/li&gt;
&lt;li&gt;Optimize infrastructure cost over time&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt; = your system’s ability to grow with demand&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vertical Scaling&lt;/strong&gt; = more power to one server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Horizontal Scaling&lt;/strong&gt; = more servers sharing the load&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Microservices&lt;/strong&gt; enable targeted, cost-effective scaling&lt;/li&gt;
&lt;li&gt;Tools like Docker, Kubernetes, Kafka, and Redis are your best friends here&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;💬 &lt;strong&gt;Over to you!&lt;/strong&gt;&lt;br&gt;
What challenges have &lt;em&gt;you&lt;/em&gt; faced while scaling backend systems? Are you using microservices or still on a monolith? Let’s share lessons in the comments.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learn polyfill in Javascript</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Mon, 28 Jul 2025 16:21:40 +0000</pubDate>
      <link>https://forem.com/keshav___dev/learn-polyfill-in-javascript-ccp</link>
      <guid>https://forem.com/keshav___dev/learn-polyfill-in-javascript-ccp</guid>
      <description>&lt;p&gt;Creating a &lt;em&gt;polyfill&lt;/em&gt; involves writing code (usually JavaScript) that emulates a newer feature in older browsers or environments that don't support that feature natively.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ What is a Polyfill?
&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;polyfill&lt;/em&gt; is a piece of code (usually JavaScript) that implements a modern web API or feature on browsers that do not support it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 Steps to Create a Polyfill
&lt;/h2&gt;

&lt;p&gt;Let’s walk through how to create one:&lt;/p&gt;




&lt;h3&gt;
  
  
  1. &lt;em&gt;Choose the Feature to Polyfill&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Pick a feature that isn't available in all target environments. Example: Array.prototype.includes&lt;/p&gt;




&lt;h3&gt;
  
  
  2. &lt;em&gt;Check if the Feature Exists&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Use a feature detection check so the polyfill only runs when needed.&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
if (!Array.prototype.includes) {&lt;br&gt;
  // Provide your own implementation&lt;br&gt;
}&lt;/p&gt;




&lt;h3&gt;
  
  
  3. &lt;em&gt;Implement the Feature&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Write the functionality in a way that mimics the native behavior as closely as possible.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ Example: Polyfill for Array.prototype.includes
&lt;/h4&gt;

&lt;p&gt;js&lt;br&gt;
if (!Array.prototype.includes) {&lt;br&gt;
  Array.prototype.includes = function(searchElement, fromIndex) {&lt;br&gt;
    if (this == null) {&lt;br&gt;
      throw new TypeError('"this" is null or not defined');&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const o = Object(this);
const len = o.length &amp;gt;&amp;gt;&amp;gt; 0;

if (len === 0) return false;

const n = fromIndex | 0;
let k = Math.max(n &amp;gt;= 0 ? n : len - Math.abs(n), 0);

while (k &amp;lt; len) {
  if (o[k] === searchElement || (typeof o[k] === 'number' &amp;amp;&amp;amp; typeof searchElement === 'number' &amp;amp;&amp;amp; isNaN(o[k]) &amp;amp;&amp;amp; isNaN(searchElement))) {
    return true;
  }
  k++;
}

return false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;br&gt;
}&lt;/p&gt;




&lt;h3&gt;
  
  
  4. &lt;em&gt;Test the Polyfill&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Use browsers that don’t support the feature and verify that your polyfill works correctly. You can use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Old browsers (via virtual machines or BrowserStack)&lt;/li&gt;
&lt;li&gt;JavaScript engines in environments like Node.js&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  5. &lt;em&gt;Distribute or Package&lt;/em&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You can include your polyfill directly in your codebase.&lt;/li&gt;
&lt;li&gt;Or, publish it as an npm package for reuse.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  📦 Tip: Use Existing Polyfills
&lt;/h3&gt;

&lt;p&gt;Before writing your own, check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/" rel="noopener noreferrer"&gt;MDN Polyfill Examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://polyfill.io/" rel="noopener noreferrer"&gt;polyfill.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Libraries like core-js, es-shims&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
    <item>
      <title>Resume-worthy project ideas for Frontend Devs</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Thu, 12 Jun 2025 16:55:43 +0000</pubDate>
      <link>https://forem.com/keshav___dev/resume-worthy-project-ideas-for-frontend-devs-4do9</link>
      <guid>https://forem.com/keshav___dev/resume-worthy-project-ideas-for-frontend-devs-4do9</guid>
      <description>&lt;h3&gt;
  
  
  1. 🧠 &lt;em&gt;Mind Mirror&lt;/em&gt; – AI-powered Mood &amp;amp; Thought Tracker
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: A daily journaling app where users type what they're feeling, and the app uses sentiment analysis + AI-generated visual metaphors to reflect back their mood.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: React, Next.js API routes, OpenAI API, localStorage or Supabase for persistence.&lt;br&gt;
&lt;em&gt;Why it's cool&lt;/em&gt;: Merges mental health awareness with generative art and AI.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. 🪞 &lt;em&gt;EchoRoom&lt;/em&gt; – Conversational Rehearsal Tool
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: A virtual space where users can rehearse conversations (job interviews, tough talks, etc.) with an AI character trained to simulate different responses.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: Next.js, WebRTC or simple audio API, OpenAI for convo logic.&lt;br&gt;
&lt;em&gt;Why it's useful&lt;/em&gt;: Targets real user needs in communication prep, social anxiety, or soft skills practice.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. 📍 &lt;em&gt;DriftMap&lt;/em&gt; – Ambient Exploration Web App
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: A generative art + map hybrid. It slowly drifts you across the globe on an abstract path with ambient music and random info snippets from locations.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: Mapbox + React + audio API.&lt;br&gt;
&lt;em&gt;Why it's like Slow Roads&lt;/em&gt;: Meditative, chill, not goal-oriented – designed for low-effort engagement.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. 📚 &lt;em&gt;NoSpoil&lt;/em&gt; – Smart Book &amp;amp; Movie Tracker
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept: Users track what they’ve watched/read and get AI-generated descriptions that **avoid spoilers&lt;/em&gt;.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: Next.js + vector search (e.g., Pinecone or Supabase Edge functions) + OpenAI.&lt;br&gt;
&lt;em&gt;Why it’s useful&lt;/em&gt;: Solves real pain point; practical and unique AI application.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. 🎭 &lt;em&gt;MicroStory&lt;/em&gt; – Tiny AI-powered Story Engine
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: Users create short micro-stories with a few parameters (theme, tone, length), and the AI crafts a story. Can also auto-generate a matching visual.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: React + OpenAI + DALL·E or 4o image generation.&lt;br&gt;
&lt;em&gt;Why it's resume-worthy&lt;/em&gt;: Combines UX, storytelling, and creativity – great to showcase frontend + API work.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. 🧩 &lt;em&gt;Fraggle&lt;/em&gt; – Spatial Memory Puzzle Game
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: A minimal, relaxing game where users memorize patterns or shapes that slowly fade and then must recreate them.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: React + Canvas/WebGL (Three.js lite)&lt;br&gt;
&lt;em&gt;Why it's different&lt;/em&gt;: Casual but cognitively engaging – great for mobile too.&lt;/p&gt;




&lt;h3&gt;
  
  
  7. ⌛ &lt;em&gt;FlowTrack&lt;/em&gt; – Flow State Habit Logger
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: Tracks when users enter "flow state" during tasks. Has a timer, mood meter, and task journal. Suggests music or lighting tweaks based on history.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: Next.js + localStorage + Spotify API (optional).&lt;br&gt;
&lt;em&gt;Why it’s unique&lt;/em&gt;: Niche productivity app with behavioral design twist.&lt;/p&gt;




&lt;h3&gt;
  
  
  8. 🎧 &lt;em&gt;EchoFeed&lt;/em&gt; – Personalized Soundscape Feed
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Concept&lt;/em&gt;: Users get a scrollable feed of ambient soundscapes (generated or curated) based on their current mood or time of day.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: React + Web Audio API + Supabase.&lt;br&gt;
&lt;em&gt;Why it’s useful&lt;/em&gt;: Aimed at remote workers, students, etc. for focus or chill.&lt;/p&gt;




&lt;h3&gt;
  
  
  Bonus: 🐌 &lt;em&gt;Urban Snail&lt;/em&gt; – "Slow Travel" Simulator
&lt;/h3&gt;

&lt;p&gt;Inspired by Slow Roads.&lt;br&gt;
&lt;em&gt;Concept&lt;/em&gt;: Simulate a slow journey across real-world cities using map/street view + procedurally generated text and ambient sound.&lt;br&gt;
&lt;em&gt;Tech&lt;/em&gt;: Next.js + Google Street View API + AI-generated travelogue narration.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>null vs undefined in JavaScript: The Tale of Two Nothing</title>
      <dc:creator>keshav Sandhu</dc:creator>
      <pubDate>Thu, 17 Apr 2025 16:34:01 +0000</pubDate>
      <link>https://forem.com/keshav___dev/null-vs-undefined-in-javascript-the-tale-of-two-nothing-4jhd</link>
      <guid>https://forem.com/keshav___dev/null-vs-undefined-in-javascript-the-tale-of-two-nothing-4jhd</guid>
      <description>&lt;h3&gt;
  
  
  🧩 What's the Deal with &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;In JavaScript, we have &lt;strong&gt;two ways to say “nothing”&lt;/strong&gt; — but they’re not the same.&lt;/p&gt;

&lt;p&gt;Both &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; represent &lt;em&gt;absence&lt;/em&gt;, but they serve &lt;strong&gt;very different purposes&lt;/strong&gt;:&lt;/p&gt;




&lt;h3&gt;
  
  
  🔍 The Quick Difference
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;null&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Type&lt;/td&gt;
&lt;td&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;object&lt;/code&gt; (legacy quirk)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Set by&lt;/td&gt;
&lt;td&gt;JavaScript (engine)&lt;/td&gt;
&lt;td&gt;Developer (manually)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Meaning&lt;/td&gt;
&lt;td&gt;"Not assigned yet"&lt;/td&gt;
&lt;td&gt;"Intentionally empty"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use Case&lt;/td&gt;
&lt;td&gt;Missing, uninitialized values&lt;/td&gt;
&lt;td&gt;Explicitly no value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  🚀 Common Use Cases
&lt;/h3&gt;

&lt;h4&gt;
  
  
  ✅ When to Use &lt;code&gt;undefined&lt;/code&gt;:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Uninitialized variables&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&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="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Missing function arguments&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="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;name&lt;/span&gt;&lt;span class="p"&gt;);&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="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Non-existent object properties&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&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;user&lt;/span&gt; &lt;span class="o"&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="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  ✅ When to Use &lt;code&gt;null&lt;/code&gt;:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Intentional absence of a value&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;selectedUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Resetting a variable&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;End of a data structure&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&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;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Missing elements in DOM&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&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;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.missing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔥 Why Does &lt;code&gt;null&lt;/code&gt; Even Matter?
&lt;/h3&gt;

&lt;p&gt;Let’s say you’re sending user data:&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;// Using undefined&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;middleName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c1"&gt;// gets stripped out in JSON.stringify&lt;/span&gt;

&lt;span class="c1"&gt;// Using null&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;middleName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;       &lt;span class="c1"&gt;// preserved: "middleName": null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;✅ &lt;code&gt;null&lt;/code&gt; = "We asked, and they don’t have a middle name."&lt;br&gt;&lt;br&gt;
❌ &lt;code&gt;undefined&lt;/code&gt; = "We don’t even know if they have one."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This difference matters in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API contracts&lt;/li&gt;
&lt;li&gt;Database schemas&lt;/li&gt;
&lt;li&gt;Validation logic&lt;/li&gt;
&lt;li&gt;Conditional rendering&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🤯 Gotchas and Fun Facts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;null == undefined&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt; (loose equality)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null === undefined&lt;/code&gt; → &lt;code&gt;false&lt;/code&gt; (strict equality)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;typeof null&lt;/code&gt; → &lt;code&gt;'object'&lt;/code&gt; (weird, but true)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  💡 TL;DR: When to Use What?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Situation&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Unset variable&lt;/td&gt;
&lt;td&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optional function argument&lt;/td&gt;
&lt;td&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Clearing a value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;End of a data structure&lt;/td&gt;
&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API says "no value" explicitly&lt;/td&gt;
&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  💬 Interview-Ready Quote:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;"&lt;strong&gt;undefined&lt;/strong&gt; is what JavaScript gives you.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;null&lt;/strong&gt; is what &lt;em&gt;you&lt;/em&gt; give JavaScript."&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
