<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khushi Patel</title>
    <description>The latest articles on DEV Community by Khushi Patel (@khushindpatel).</description>
    <link>https://dev.to/khushindpatel</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%2F1055368%2Fe0780331-7974-49ea-ba06-89417152f136.jpg</url>
      <title>DEV Community: Khushi Patel</title>
      <link>https://dev.to/khushindpatel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khushindpatel"/>
    <language>en</language>
    <item>
      <title>Implement LFU using LRU</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 02 Apr 2026 09:27:06 +0000</pubDate>
      <link>https://dev.to/khushindpatel/implement-lfu-using-lru-8fl</link>
      <guid>https://dev.to/khushindpatel/implement-lfu-using-lru-8fl</guid>
      <description>&lt;h3&gt;
  
  
  📌 Core Idea
&lt;/h3&gt;

&lt;p&gt;LFU (Least Frequently Used) means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove the &lt;strong&gt;least frequently used&lt;/strong&gt; key&lt;/li&gt;
&lt;li&gt;If multiple keys have same frequency → remove &lt;strong&gt;least recently used (LRU)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  📦 Data Structures Used
&lt;/h3&gt;

&lt;p&gt;We maintain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;key → node&lt;/code&gt; (for O(1) access)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;freq → doubly linked list&lt;/code&gt; (group nodes by frequency)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;minFreq&lt;/code&gt; (track minimum frequency in cache)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧱 Structure Visualization
&lt;/h3&gt;

&lt;p&gt;Freq = 1 → [ most recent .... least recent ]&lt;br&gt;&lt;br&gt;
Freq = 2 → [ most recent .... least recent ]&lt;br&gt;&lt;br&gt;
Freq = 3 → [ most recent .... least recent ]  &lt;/p&gt;

&lt;p&gt;Each frequency has its &lt;strong&gt;own LRU list&lt;/strong&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  🚀 Example Walkthrough
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Capacity = 2
&lt;/h4&gt;


&lt;h4&gt;
  
  
  Step 1: put(1,10)
&lt;/h4&gt;

&lt;p&gt;Freq 1: [1]&lt;br&gt;&lt;br&gt;
minFreq = 1  &lt;/p&gt;


&lt;h4&gt;
  
  
  Step 2: put(2,20)
&lt;/h4&gt;

&lt;p&gt;Freq 1: &lt;a href="https://dev.to2%20is%20most%20recent"&gt;2, 1&lt;/a&gt;&lt;br&gt;&lt;br&gt;
minFreq = 1  &lt;/p&gt;


&lt;h4&gt;
  
  
  Step 3: get(1)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Access key &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Increase its frequency: 1 → 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Freq 1: [2]&lt;br&gt;&lt;br&gt;
Freq 2: [1]&lt;br&gt;&lt;br&gt;
minFreq = 1  &lt;/p&gt;

&lt;p&gt;👉 We removed &lt;code&gt;1&lt;/code&gt; from freq 1 and added to freq 2&lt;/p&gt;


&lt;h4&gt;
  
  
  Step 4: put(3,30)
&lt;/h4&gt;

&lt;p&gt;Cache is FULL → eviction needed  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;minFreq = 1
&lt;/li&gt;
&lt;li&gt;Look at Freq 1 → [2]
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Remove &lt;code&gt;2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After insertion:&lt;/p&gt;

&lt;p&gt;Freq 1: [3]&lt;br&gt;&lt;br&gt;
Freq 2: [1]&lt;br&gt;&lt;br&gt;
minFreq = 1  &lt;/p&gt;


&lt;h4&gt;
  
  
  Step 5: get(3)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Move &lt;code&gt;3&lt;/code&gt; from freq 1 → freq 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Freq 1: []&lt;br&gt;&lt;br&gt;
Freq 2: [3, 1]&lt;br&gt;&lt;br&gt;
minFreq = 2   (freq 1 is empty now)  &lt;/p&gt;


&lt;h4&gt;
  
  
  Step 6: put(4,40)
&lt;/h4&gt;

&lt;p&gt;Cache full → eviction  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;minFreq = 2
&lt;/li&gt;
&lt;li&gt;Freq 2 → [3, 1]
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Remove LRU → &lt;code&gt;1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After insertion:&lt;/p&gt;

&lt;p&gt;Freq 1: [4]&lt;br&gt;&lt;br&gt;
Freq 2: [3]&lt;br&gt;&lt;br&gt;
minFreq = 1  &lt;/p&gt;


&lt;h3&gt;
  
  
  🔥 Key Observations
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Why multiple lists?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Different frequencies → cannot maintain in single list
&lt;/li&gt;
&lt;li&gt;Each frequency maintains its own LRU order
&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  2. Why minFreq?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Helps directly find which list to evict from in O(1)
&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  3. Why doubly linked list?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;O(1) removal
&lt;/li&gt;
&lt;li&gt;Maintain LRU order inside same frequency
&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  🧠 Mental Model
&lt;/h3&gt;

&lt;p&gt;Think of LFU like books:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shelf 1 → least used books
&lt;/li&gt;
&lt;li&gt;Shelf 2 → moderately used
&lt;/li&gt;
&lt;li&gt;Shelf 3 → most used
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When removing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pick least used shelf
&lt;/li&gt;
&lt;li&gt;Remove oldest book from that shelf
&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;
  
  
  🧩 Mapping to Code
&lt;/h3&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;Code&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Increase frequency&lt;/td&gt;
&lt;td&gt;updateFreq(node)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remove LRU&lt;/td&gt;
&lt;td&gt;list-&amp;gt;tail-&amp;gt;prev&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Track minimum&lt;/td&gt;
&lt;td&gt;minFreq&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insert new node&lt;/td&gt;
&lt;td&gt;freq = 1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h3&gt;
  
  
  🚨 Common Mistake
&lt;/h3&gt;

&lt;p&gt;When a frequency list becomes empty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;minFreq&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;minFreq&lt;/span&gt;&lt;span class="o"&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 you don’t update minFreq, eviction will break&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LFUCache&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;public:&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;freq&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="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;public:&lt;/span&gt;
        &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Node&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="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="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Node&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="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="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;addFront&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;removeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;prevv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;nextt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;prevv&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;nextt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prevv&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minFreq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;unordered_map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// key -&amp;gt; node&lt;/span&gt;
    &lt;span class="n"&gt;unordered_map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;*&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// freq -&amp;gt; DLL&lt;/span&gt;

    &lt;span class="n"&gt;LFUCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;minFreq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;updateFreq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;removeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;minFreq&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;minFreq&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;addFront&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;return&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="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;updateFreq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
            &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;updateFreq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;minFreq&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
            &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;nodeToRemove&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;erase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nodeToRemove&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;removeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nodeToRemove&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;newNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;minFreq&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&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="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;freqList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;freqList&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="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;freqList&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="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;addFront&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;keyNode&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newNode&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;



</description>
      <category>datastructures</category>
      <category>dsa</category>
      <category>programming</category>
    </item>
    <item>
      <title>7-Day Beginner’s Mindmap to Learn GenAI</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Tue, 15 Jul 2025 04:26:23 +0000</pubDate>
      <link>https://dev.to/khushindpatel/7-day-beginners-mindmap-to-learn-genai-4flb</link>
      <guid>https://dev.to/khushindpatel/7-day-beginners-mindmap-to-learn-genai-4flb</guid>
      <description>&lt;p&gt;Perfect for anyone curious about ChatGPT, LLMs, image generation &amp;amp; more!&lt;br&gt;
Each day has clear topics + free resources (courses, videos, articles) 🧠✨&lt;/p&gt;

&lt;p&gt;👉 Explore the full mindmap here: &lt;a href="https://miro.com/app/board/uXjVJeJ7gJk=/?share_link_id=128758728459" rel="noopener noreferrer"&gt;Link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow on Instagram &lt;a href="https://www.instagram.com/codeandcrunch/" rel="noopener noreferrer"&gt;CodeAndCrunch&lt;/a&gt;&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>llm</category>
      <category>ai</category>
      <category>learning</category>
    </item>
    <item>
      <title>Understanding Video Streaming and Optimize Media Downloads 📽️📂</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Tue, 04 Mar 2025 12:48:33 +0000</pubDate>
      <link>https://dev.to/khushindpatel/understanding-video-streaming-and-optimize-media-downloads-k6i</link>
      <guid>https://dev.to/khushindpatel/understanding-video-streaming-and-optimize-media-downloads-k6i</guid>
      <description>&lt;p&gt;Video streaming has become an integral part of our digital experience, powering everything from YouTube and Netflix to social media platforms like Facebook, Twitter (X), and Instagram. While streaming is optimized for seamless playback, there are times when users might want to download content for offline access. This raises the question: How does video streaming work, and how can we optimize media downloads while staying within ethical boundaries?&lt;/p&gt;

&lt;p&gt;In this post, we’ll break down the core principles of video streaming, explore how video downloads work, and discuss ways to optimize media retrieval efficiently. &lt;/p&gt;

&lt;h2&gt;
  
  
  How Video Streaming Works ⚒️
&lt;/h2&gt;

&lt;p&gt;Streaming works by delivering media data in small chunks rather than requiring users to download the entire file before playback. Here’s a breakdown of key concepts:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Streaming Protocols
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Live Streaming (HLS)&lt;/strong&gt;: Used by Apple devices and many streaming platforms, HLS splits videos into small &lt;code&gt;.ts&lt;/code&gt;segments, which are loaded dynamically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Adaptive Streaming over HTTP (DASH):&lt;/strong&gt; A widely used protocol that adjusts video quality based on network conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-Time Messaging Protocol (RTMP):&lt;/strong&gt; Previously popular for live streaming but now largely replaced by HLS/DASH.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Video Encoding &amp;amp; Compression
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Codecs (H.264, H.265, VP9, AV1):&lt;/strong&gt; Used to compress video files while maintaining quality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bitrate Adaptation&lt;/strong&gt;: Streaming platforms adjust video quality based on bandwidth to avoid buffering.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Content Delivery Networks (CDNs)
&lt;/h3&gt;

&lt;p&gt;CDNs store video files across multiple servers worldwide to reduce latency and improve load times.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Media Downloads Work
&lt;/h2&gt;

&lt;p&gt;Downloading a video is different from streaming because it involves retrieving the full file instead of fetching segments dynamically. However, many platforms restrict direct downloads to protect content rights. Here’s how media downloads typically work:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Direct File Download
&lt;/h3&gt;

&lt;p&gt;Some platforms provide direct download options (e.g., YouTube Premium for offline viewing).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. M3U8 Parsing (HLS Streams)
&lt;/h3&gt;

&lt;p&gt;Some media files are segmented into .m3u8 playlists containing multiple &lt;code&gt;.ts&lt;/code&gt; files. These need to be reconstructed into a full video. &lt;a href="https://www.fastpix.io/blog/a-complete-guide-to-m3u8-files-in-hls-streaming" rel="noopener noreferrer"&gt;read more&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. API-Based Downloads
&lt;/h3&gt;

&lt;p&gt;Some services provide APIs to fetch media content legally, All in One Downloader &lt;a href="https://www.allinonedownloader.co/" rel="noopener noreferrer"&gt;All in One Downloader&lt;/a&gt; is a great example of this which allow user to download video from multiple social media platform&lt;/p&gt;

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

&lt;p&gt;By leveraging the right technologies and understanding video formats, you can enhance your workflow and make media retrieval more seamless. &lt;/p&gt;

&lt;p&gt;What are your thoughts on video downloads and streaming optimization? Have you built any tools to enhance media retrieval? Let’s discuss in the comments! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>news</category>
      <category>opensource</category>
    </item>
    <item>
      <title>you know about this tools?</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 30 Jan 2025 12:56:42 +0000</pubDate>
      <link>https://dev.to/khushindpatel/-5he</link>
      <guid>https://dev.to/khushindpatel/-5he</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/khushindpatel" 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%2F1055368%2Fe0780331-7974-49ea-ba06-89417152f136.jpg" alt="khushindpatel"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/khushindpatel/5-open-source-tools-every-saas-founder-should-use-for-free-1joi" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;5 Open Source Tools Every SaaS Founder Should Use for Free 🚀&lt;/h2&gt;
      &lt;h3&gt;Khushi Patel ・ Jan 30&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#startup&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#marketing&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#saas&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>startup</category>
      <category>marketing</category>
      <category>saas</category>
      <category>javascript</category>
    </item>
    <item>
      <title>5 Open Source Tools Every SaaS Founder Should Use for Free 🚀</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 30 Jan 2025 12:52:44 +0000</pubDate>
      <link>https://dev.to/khushindpatel/5-open-source-tools-every-saas-founder-should-use-for-free-1joi</link>
      <guid>https://dev.to/khushindpatel/5-open-source-tools-every-saas-founder-should-use-for-free-1joi</guid>
      <description>&lt;p&gt;Starting a SaaS business is exciting—until you realize how expensive it can get. Hosting, analytics, support, marketing... it all adds up!&lt;/p&gt;

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

&lt;p&gt;But what if I told you there are powerful open-source tools that can save you thousands of dollars while giving you full control over your data?&lt;/p&gt;

&lt;p&gt;Yep, you heard that right! Here are five open-source gems every SaaS founder should be using (for free!) to build, grow, and scale their startup.&lt;/p&gt;

&lt;p&gt;1️⃣ Plausible – Privacy-Friendly Analytics 📊&lt;br&gt;
Why pay for Google Analytics when you can own your data? Plausible is an open-source, lightweight analytics tool that gives you clear insights without slowing down your website. Plus, it’s GDPR compliant by design—no cookies, no tracking nightmares.&lt;/p&gt;

&lt;p&gt;🔹 Why you'll love it?&lt;br&gt;
✔️ Simple, clean UI (No need for a data science degree!)&lt;br&gt;
✔️ No invasive tracking—privacy-first 🌍&lt;br&gt;
✔️ Self-host it for zero monthly costs&lt;/p&gt;

&lt;p&gt;💡 Perfect for: Founders who care about privacy and want an easy-to-understand analytics dashboard.&lt;/p&gt;

&lt;p&gt;👉 Check it out: &lt;a href="//plausible.io"&gt;plausible.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2️⃣ Chatwoot – Open-Source Live Chat &amp;amp; Support 💬&lt;br&gt;
Forget Intercom’s hefty price tag! Chatwoot is an open-source alternative that helps you chat with customers in real-time, manage support tickets, and automate conversations.&lt;/p&gt;

&lt;p&gt;🔹 Why you'll love it?&lt;br&gt;
✔️ Omnichannel support (Website, WhatsApp, Facebook, etc.)&lt;br&gt;
✔️ Customizable &amp;amp; developer-friendly&lt;br&gt;
✔️ No per-agent pricing, scale for free!&lt;/p&gt;

&lt;p&gt;💡 Perfect for: SaaS founders who want direct customer engagement without burning a hole in their wallet.&lt;/p&gt;

&lt;p&gt;👉 Check it out: &lt;a href="//chatwoot.com"&gt;chatwoot.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3️⃣ PostHog – Product Analytics on Steroids 🔥&lt;br&gt;
Want to know how users interact with your SaaS? PostHog gives you session replays, feature flags, and event tracking all in one place. It’s like Mixpanel &amp;amp; Hotjar had an open-source baby.&lt;/p&gt;

&lt;p&gt;🔹 Why you'll love it?&lt;br&gt;
✔️ Event-based analytics (track anything!)&lt;br&gt;
✔️ User session recordings for UI/UX insights&lt;br&gt;
✔️ Feature flags to test new features safely&lt;/p&gt;

&lt;p&gt;💡 Perfect for: SaaS founders who want deep product insights to optimize their UX.&lt;/p&gt;

&lt;p&gt;👉 Check it out: &lt;a href="//posthog.com"&gt;posthog.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4️⃣ NocoDB – Open-Source Airtable Alternative 🏗️&lt;br&gt;
Who needs Airtable when NocoDB lets you turn any database into a smart, spreadsheet like interface? You can build admin panels, internal tools, and dashboards—no coding required!&lt;/p&gt;

&lt;p&gt;🔹 Why you'll love it?&lt;br&gt;
✔️ Works with MySQL, PostgreSQL, and more&lt;br&gt;
✔️ Drag &amp;amp; drop interface, just like Airtable&lt;br&gt;
✔️ Self-host it = No monthly fees!&lt;/p&gt;

&lt;p&gt;💡 Perfect for: SaaS founders who need a database-driven app without expensive SaaS subscriptions.&lt;/p&gt;

&lt;p&gt;👉 Check it out: &lt;a href="//nocodb.com"&gt;nocodb.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5️⃣ Mautic – Open-Source Marketing Automation 🎯&lt;br&gt;
Want to automate email campaigns, lead scoring, and customer journeys without paying for HubSpot or ActiveCampaign? Mautic is your answer!&lt;/p&gt;

&lt;p&gt;🔹 Why you'll love it?&lt;br&gt;
✔️ Powerful marketing automation (emails, SMS, social, web)&lt;br&gt;
✔️ Advanced segmentation &amp;amp; lead scoring&lt;br&gt;
✔️ Self-hosted = Own your data + Save $$$&lt;/p&gt;

&lt;p&gt;💡 Perfect for: SaaS founders who need automated marketing on a budget.&lt;/p&gt;

&lt;p&gt;👉 Check it out: &lt;a href="//mautic.org"&gt;mautic.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Final Thoughts 💡&lt;br&gt;
SaaS founders, stop burning cash on expensive tools when open-source alternatives are just as powerful! These tools let you:&lt;br&gt;
✅ Cut costs 💰&lt;br&gt;
✅ Own your data 🔐&lt;br&gt;
✅ Customize and scale your startup your way 🚀&lt;/p&gt;

&lt;p&gt;Which open-source tool are you most excited to try? Drop a comment below! 👇&lt;/p&gt;

</description>
      <category>startup</category>
      <category>marketing</category>
      <category>saas</category>
      <category>javascript</category>
    </item>
    <item>
      <title>The DSA Revision Mindmap</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Sat, 11 Jan 2025 14:52:11 +0000</pubDate>
      <link>https://dev.to/khushindpatel/the-dsa-revision-mindmap-3d2</link>
      <guid>https://dev.to/khushindpatel/the-dsa-revision-mindmap-3d2</guid>
      <description>&lt;p&gt;The DSA Revision Mindmap is your ultimate companion for revisiting core concepts in Data Structures and Algorithms. It provides a bird’s-eye view of essential topics and key problem-solving strategies, making your preparation efficient and well-structured.&lt;/p&gt;

&lt;p&gt;This mindmap organizes complex topics into digestible sections, including data structures like arrays, trees, and graphs, as well as algorithmic techniques such as dynamic programming, greedy methods, and backtracking. It also integrates mathematical foundations, complexity analysis, and real-world problem patterns to ensure you’re prepared for coding interviews and competitive programming challenges.&lt;/p&gt;

&lt;p&gt;Whether you’re gearing up for interviews, tackling coding contests, or simply strengthening your fundamentals, this mindmap helps you stay focused and systematic, covering all the essentials you need to excel in DSA.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://miro.com/app/board/uXjVL1_8PFI=/?share_link_id=385430008121" rel="noopener noreferrer"&gt;https://miro.com/app/board/uXjVL1_8PFI=/?share_link_id=385430008121&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>coding</category>
      <category>dsa</category>
    </item>
    <item>
      <title>Mindmap for graphQL in 7 days</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Wed, 18 Sep 2024 16:54:34 +0000</pubDate>
      <link>https://dev.to/khushindpatel/mindmap-for-graphql-in-7-days-4221</link>
      <guid>https://dev.to/khushindpatel/mindmap-for-graphql-in-7-days-4221</guid>
      <description>&lt;p&gt;Here i have create mindmap for graphql &lt;br&gt;
for each days it has some topics and tasks attached &lt;br&gt;
for each days it attached one youtube video &lt;br&gt;
link :&lt;br&gt;
&lt;a href="https://miro.com/app/board/uXjVLdCFL7I=/" rel="noopener noreferrer"&gt;https://miro.com/app/board/uXjVLdCFL7I=/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding ! 🫶🏻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Lerna – The key of Monorepo Management</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 12 Sep 2024 03:37:38 +0000</pubDate>
      <link>https://dev.to/khushindpatel/lerna-the-key-of-monorepo-management-4e7n</link>
      <guid>https://dev.to/khushindpatel/lerna-the-key-of-monorepo-management-4e7n</guid>
      <description>&lt;p&gt;Welcome Back to Monorepo Castle!&lt;br&gt;
The castle is now built, and every room (project) is in place. But without the right management, things could get messy. Who will help the castle run smoothly? That’s when Lerna enters—a powerful wizard with magical commands that keep everything in order.&lt;/p&gt;

&lt;p&gt;Lerna is your guide in the land of monorepo, making sure all the rooms (projects) are in sync, all the packages are linked, and nothing falls apart.&lt;/p&gt;
&lt;h2&gt;
  
  
  Meet the Magical Wizard: Lerna
&lt;/h2&gt;

&lt;p&gt;Lerna isn't just any wizard—it’s a super wizard designed to make your life easier while managing multiple projects in one repo. Let’s take a peek at some of Lerna’s spells (commands):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. lerna init – The “Let’s Build a Castle” Spell&lt;/strong&gt;&lt;br&gt;
This is where it all starts. You summon Lerna with this command, and it sets up the structure for your monorepo. It’s like laying the foundation for your castle—each room has its place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then define your workspaces in package.json. With Yarn or pnpm, you can list all the packages that should be managed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
{
  "private": true,
  "workspaces": [
    "packages/*"
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells the package manager to treat everything inside the packages/ directory as individual sub-projects (frontend, backend, shared libraries, etc.).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Yarn or pnpm for Dependency Management&lt;/strong&gt;&lt;br&gt;
Previously, Lerna had lerna bootstrap to link dependencies across packages, but this has been deprecated. Instead, use Yarn or pnpm for this task. you can run any of bellow command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn install
pnpm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This automatically links all the projects inside your monorepo, so they can share dependencies. It also deduplicates packages to reduce size, making the installation process faster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Running Commands Across Packages&lt;/strong&gt;&lt;br&gt;
One of the most powerful features of Lerna is still intact: running scripts across multiple packages in the monorepo. If your monorepo has both a frontend and backend, for example, you can run build or test commands across both without switching directories.&lt;/p&gt;

&lt;p&gt;Run the build script in every package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lerna will go into each package and execute the build script, which is extremely useful when you want to ensure all packages are in sync before deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Versioning &amp;amp; Publishing&lt;/strong&gt;&lt;br&gt;
Lerna’s original focus remains unchanged: versioning and publishing.&lt;br&gt;
&lt;strong&gt;Versioning&lt;/strong&gt;: Lerna will automatically bump versions for your packages based on the changes you’ve made. This ensures that when you make updates, version numbers are consistent across the whole project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Publishing&lt;/strong&gt;: When it’s time to release, you can use Lerna to publish all packages at once, or selectively, depending on your needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Lerna by your side, managing a monorepo becomes an absolute easy. From syncing dependencies to running scripts across projects, Lerna keeps the castle organized, efficient, and fast.&lt;/p&gt;

&lt;p&gt;Stay tuned for more wizardry as we explore other tools in this magical land of web development. ✨&lt;/p&gt;

&lt;p&gt;till then, Happy Coding ! 🫶🏻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Monorepo – The Magic of One Repo you must know as full stack developer</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Sat, 07 Sep 2024 09:16:01 +0000</pubDate>
      <link>https://dev.to/khushindpatel/monorepo-the-magic-of-one-repo-you-must-know-as-full-stack-developer-3188</link>
      <guid>https://dev.to/khushindpatel/monorepo-the-magic-of-one-repo-you-must-know-as-full-stack-developer-3188</guid>
      <description>&lt;p&gt;So nextJS is inveted in 2016 people befefore that &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Once Upon a Time, in the Land of Repos...&lt;/strong&gt;&lt;br&gt;
There was chaos. Developers were running around, managing multiple repositories like juggling fireballs. The frontend was in one repo, backend in another, and libraries were scattered across the kingdom Then, one day developers comes up with solution &lt;strong&gt;Monorepo&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Monorepo is like the grand library where all your books (code) are stored in one place. No more running around fetching them from different locations. You simply open one door, and all your projects are neatly tucked in!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Monorepo?
&lt;/h2&gt;

&lt;p&gt;Imagine a castle (repo) with many rooms (folders). Each room has its own purpose:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Frontend&lt;/strong&gt;: Where the React code lives, playing with cool user interfaces.&lt;br&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: The secret chamber of Node.js where data flows&lt;br&gt;
&lt;strong&gt;Shared Components&lt;/strong&gt;: The royal pantry, stocked with reusable goodies for all the rooms.&lt;br&gt;
All these rooms are part of the same castle (mono repository). You don’t have to go from one castle to another to find what you need—it’s all under one roof!&lt;/p&gt;

&lt;h2&gt;
  
  
  What's problem before this?
&lt;/h2&gt;

&lt;p&gt;Traditionally, you might create two separate repositories. one for the frontend and one for the backend. At first, this seems simple. But as the project grows, you run into some annoying problems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The frontend repo has its own set of dependencies, pipelines, and code.&lt;/li&gt;
&lt;li&gt;The backend repo is also completely separate, with its own setup.&lt;/li&gt;
&lt;li&gt;You have to manually sync shared code (like authentication logic) between the two repos&lt;/li&gt;
&lt;li&gt;The frontend and backend use similar libraries, but they’re often running different versions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Monorepo Solves These Problems:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;All-in-One Repo&lt;/strong&gt;: Frontend and backend live together in one repo. No more switching, making development smoother.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared Code Folder&lt;/strong&gt;: Utility functions are shared between frontend and backend without duplication. Update once, and it's reflected everywhere. You can Start both parts of the app with one command&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unified Dependencies&lt;/strong&gt;: All packages use the same versions, avoiding compatibility issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single CI/CD Pipeline&lt;/strong&gt;: One pipeline handles the entire app, making deployments and testing faster and error-free.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But wait—how do we manage such a grand castle of projects efficiently?&lt;/p&gt;

&lt;p&gt;Enter Lerna, the magical wizard who keeps everything in the castle running smoothly. And that’s where our next blog will come into picture.....&lt;/p&gt;

&lt;p&gt;Stay tuned ! 🔔&lt;/p&gt;

&lt;p&gt;till then happy coding ! 🫶🏻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>node</category>
    </item>
    <item>
      <title>Handling Errors in Node.js: Turning Oops into Success 🚀</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Sun, 01 Sep 2024 04:02:11 +0000</pubDate>
      <link>https://dev.to/khushindpatel/handling-errors-in-nodejs-turning-oops-into-success-1h03</link>
      <guid>https://dev.to/khushindpatel/handling-errors-in-nodejs-turning-oops-into-success-1h03</guid>
      <description>&lt;p&gt;Errors are like uninvited guests, Let me share with you how I’ve learned to handle errors in Node.js, transforming those "Oops" moments into success.&lt;br&gt;
The key point here is "&lt;em&gt;&lt;strong&gt;Expect the Unexpected&lt;/strong&gt;&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgi4pazayqoajbus5rgpk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgi4pazayqoajbus5rgpk.gif" alt="Expect" width="640" height="358"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding Errors: The Usual Suspects
&lt;/h2&gt;

&lt;p&gt;Before we dive into handling errors, Let me recall you types of ERROR In Node.js, errors typically fall into a few categories:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax Errors&lt;/strong&gt;: (&lt;em&gt;They usually happen when you forget a } or add an extra&lt;/em&gt;). Node.js will shout at you (in red text) and refuse to run your code until you fix it (Thanks to compiler! 🙏🏻).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Runtime Errors&lt;/strong&gt;: These occur when your code tries to do something impossible(&lt;em&gt;reading a property of undefined&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logical Errors&lt;/strong&gt;: These are the sneaky ones. Your code runs without crashing, but it doesn’t do what it’s supposed to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operational Errors&lt;/strong&gt;: They’re often caused by factors outside of your control, but they’re still your responsibility to handle (when your database suddenly decided to take nap!!😂).&lt;/p&gt;
&lt;h2&gt;
  
  
  Error Handling: My Go-To Techniques
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Try-Catch: The First Line of Defence&lt;/strong&gt;&lt;br&gt;
When working with asynchronous code, try-catch is your best friend. I’ve found that wrapping code in a try-catch block can save you a lot of headaches.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
    try {
        const data = await someAsyncFunction();
        return data;
    } catch (error) {
        console.error('Error fetching data:', error.message);
        throw new Error('Failed to fetch data');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Centralized Error Handling: Keeping Things Organized&lt;/strong&gt;&lt;br&gt;
 I centralize my error handling in one place—usually a middleware function. This approach keeps my code clean and makes it easier to manage errors across the entire application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use((err, req, res, next) =&amp;gt; {
    console.error(err.stack);
    res.status(500).json({ message: 'Something went wrong!' });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Custom Error Classes: Making Errors Work for You&lt;/strong&gt;&lt;br&gt;
 I create custom error classes. This allows me to throw meaningful errors that can be handled differently depending on the situation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class NotFoundError extends Error {
    constructor(message) {
        super(message);
        this.name = 'NotFoundError';
        this.statusCode = 404;
    }
}

throw new NotFoundError('Resource not found');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Promise Rejection Handling: Because Promises Don’t Always Keep Theirs&lt;/strong&gt;&lt;br&gt;
Working with Promises? Then you’ve probably run into the dreaded unhandled promise rejection. It’s important to catch these errors too, as they can easily slip by unnoticed if you’re not careful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;process.on('unhandledRejection', (reason, promise) =&amp;gt; {
    console.error('Unhandled Rejection at:', promise, 'reason:', reason);
    // Application-specific logging, throwing an error, or other logic here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion: Turning Oops into Success
&lt;/h2&gt;

&lt;p&gt;By handling errors thoughtfully and proactively, you not only improve your code but also create a better experience for your users.&lt;/p&gt;

&lt;p&gt;Happy coding ! 🫶🏻&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Types of Middleware: The Different Flavors</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 29 Aug 2024 05:34:36 +0000</pubDate>
      <link>https://dev.to/khushindpatel/types-of-middleware-the-different-flavors-3p84</link>
      <guid>https://dev.to/khushindpatel/types-of-middleware-the-different-flavors-3p84</guid>
      <description>&lt;p&gt;After reading last post let's see types of middleware in ExpressJs ,Middleware comes in different flavors(😛), each serving a unique purpose:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Application-level Middleware:&lt;/strong&gt; This is like the main ingredient. You add it to your whole application, and it runs on every request.🫡&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use((req, res, next) =&amp;gt; {
    console.log('This runs on every request!');
    next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Router-level Middleware:&lt;/strong&gt; This is more like a specialty topping. It’s used for specific routes or groups of routes.🤓&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const router = express.Router();
router.use('/special', (req, res, next) =&amp;gt; {
    console.log('Special route middleware!');
    next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Built-in Middleware:&lt;/strong&gt; These are like pre-made sauces that come with Express, such as express.json() for parsing JSON. 😌&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(express.json());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Error-handling Middleware:&lt;/strong&gt; This is the chef’s secret weapon. It catches any errors and serves up a custom response. 😎&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use((err, req, res, next) =&amp;gt; {
    console.error(err.stack);
    res.status(500).send('Something broke!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Power of Composing Middleware 🫱🏻‍🫲🏽
&lt;/h2&gt;

&lt;p&gt;One of the coolest things about middleware is that you can stack them together to create complex workflows. Each middleware function can either end the request-response cycle or pass control to the next function using next(). This makes it easy to add features like authentication, logging, error handling, and more—just like adding layers to your sandwich.&lt;br&gt;
Here’s how you might use middleware to protect a route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const authenticate = (req, res, next) =&amp;gt; {
    if (req.isAuthenticated()) {
        return next();
    }
    res.redirect('/login');
};

app.get('/dashboard', authenticate, (req, res) =&amp;gt; {
    res.send('Welcome to your dashboard!');
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the authenticate middleware checks if the user is authenticated before allowing them to access the dashboard.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Conclusion: Middleware Mastery 👩🏻‍🍳 *&lt;/em&gt;&lt;br&gt;
Middleware is truly the secret sauce of Express.js, adding layers of functionality to your Node.js applications. Whether you’re handling requests, managing responses, or catching errors, mastering middleware will make your code cleaner, more organised, and a lot more powerful.&lt;/p&gt;

&lt;p&gt;So next time you’re building an Express.js app, think about the flavors you can add with middleware. Mix, match, and create your own secret sauce—it’s what makes your application uniquely yours!&lt;/p&gt;

&lt;p&gt;Happy C̶o̶o̶k̶i̶n̶g̶ Coding! 🫶🏻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>node</category>
    </item>
    <item>
      <title>Types of Middleware: The Different Flavors 😋</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 29 Aug 2024 05:34:36 +0000</pubDate>
      <link>https://dev.to/khushindpatel/types-of-middleware-the-different-flavors-171a</link>
      <guid>https://dev.to/khushindpatel/types-of-middleware-the-different-flavors-171a</guid>
      <description>&lt;p&gt;After reading last post let's see types of middleware in ExpressJs ,Middleware comes in different flavours(😛), each serving a unique purpose&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;1. Application-level Middleware:&lt;/strong&gt; This is like the main ingredient. You add it to your whole application, and it runs on every request.🫡&lt;/p&gt;

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

app.use((req, res, next) =&amp;gt; {
    console.log('This runs on every request!');
    next();
});


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. Router-level Middleware:&lt;/strong&gt; This is more like a specialty topping. It’s used for specific routes or groups of routes.🤓&lt;/p&gt;

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

const router = express.Router();
router.use('/special', (req, res, next) =&amp;gt; {
    console.log('Special route middleware!');
    next();
});


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. Built-in Middleware:&lt;/strong&gt; These are like pre-made sauces that come with Express, such as express.json() for parsing JSON. 😌&lt;/p&gt;

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

app.use(express.json());


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;4. Error-handling Middleware:&lt;/strong&gt; This is the chef’s secret weapon. It catches any errors and serves up a custom response. 😎&lt;/p&gt;

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

app.use((err, req, res, next) =&amp;gt; {
    console.error(err.stack);
    res.status(500).send('Something broke!');
});


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  The Power of Composing Middleware 🫱🏻‍🫲🏽
&lt;/h2&gt;

&lt;p&gt;One of the coolest things about middleware is that you can stack them together to create complex workflows. Each middleware function can either end the request-response cycle or pass control to the next function using next(). This makes it easy to add features like authentication, logging, error handling, and more—just like adding layers to your sandwich.&lt;br&gt;
Here’s how you might use middleware to protect a route:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const authenticate = (req, res, next) =&amp;gt; {
    if (req.isAuthenticated()) {
        return next();
    }
    res.redirect('/login');
};

app.get('/dashboard', authenticate, (req, res) =&amp;gt; {
    res.send('Welcome to your dashboard!');
});



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, the authenticate middleware checks if the user is authenticated before allowing them to access the dashboard.&lt;/p&gt;

&lt;p&gt;*Conclusion: Middleware Mastery 👩🏻‍🍳 *&lt;br&gt;
Middleware is truly the secret sauce of Express.js, adding layers of functionality to your Node.js applications. Whether you’re handling requests, managing responses, or catching errors, mastering middleware will make your code cleaner, more organised, and a lot more powerful.&lt;/p&gt;

&lt;p&gt;So next time you’re building an Express.js app, think about the flavors you can add with middleware. Mix, match, and create your own secret sauce—it’s what makes your application uniquely yours!&lt;/p&gt;

&lt;p&gt;Happy C̶o̶o̶k̶i̶n̶g̶ Coding! 🫶🏻&lt;/p&gt;

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