<?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: Anuj Singh</title>
    <description>The latest articles on DEV Community by Anuj Singh (@singhanuj620).</description>
    <link>https://dev.to/singhanuj620</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%2F317284%2Fee52e1ac-f2fe-4452-8739-a04a8275a0a8.JPG</url>
      <title>DEV Community: Anuj Singh</title>
      <link>https://dev.to/singhanuj620</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/singhanuj620"/>
    <language>en</language>
    <item>
      <title>Building a Lightning-Fast NSE Stock Data Scraper: From API Calls to Full-Stack Web App</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Wed, 27 Aug 2025 19:00:38 +0000</pubDate>
      <link>https://dev.to/singhanuj620/building-a-lightning-fast-nse-stock-data-scraper-from-api-calls-to-full-stack-web-app-4hl7</link>
      <guid>https://dev.to/singhanuj620/building-a-lightning-fast-nse-stock-data-scraper-from-api-calls-to-full-stack-web-app-4hl7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Ever tried to download historical stock data from the National Stock Exchange (NSE) of India and found yourself waiting hours for selenium-based scrapers to crawl through web pages? I built a solution that's &lt;strong&gt;10x faster&lt;/strong&gt; using direct API calls and wrapped it in a beautiful full-stack web application. &lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;Live Demo&lt;/strong&gt;: &lt;a href="https://nse-scrap.onrender.com" rel="noopener noreferrer"&gt;https://nse-scrap.onrender.com&lt;/a&gt;&lt;br&gt;&lt;br&gt;
📁 &lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/singhanuj620/nse_scrap" rel="noopener noreferrer"&gt;https://github.com/singhanuj620/nse_scrap&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 What We're Building
&lt;/h2&gt;

&lt;p&gt;A complete stock data scraping solution that includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend API scraper&lt;/strong&gt; using Node.js with direct NSE API calls&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React frontend&lt;/strong&gt; with real-time progress tracking&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session management&lt;/strong&gt; for concurrent scraping jobs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Downloadable ZIP exports&lt;/strong&gt; of all scraped data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive UI&lt;/strong&gt; with modern design&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  🎯 The Problem with Traditional Scraping
&lt;/h2&gt;

&lt;p&gt;Most stock data scrapers rely on browser automation tools like Selenium or Puppeteer. While functional, they have significant drawbacks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Slow&lt;/strong&gt;: Loading full web pages for each request&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unreliable&lt;/strong&gt;: Breaking when UI changes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource-heavy&lt;/strong&gt;: Requires browser instances&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limited scalability&lt;/strong&gt;: Can't handle many concurrent requests&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  💡 The Solution: Direct API Approach
&lt;/h2&gt;

&lt;p&gt;Instead of scraping web pages, I discovered that NSE provides direct API endpoints for historical data. Here's the core approach:&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;class&lt;/span&gt; &lt;span class="nc"&gt;NSEAPIClient&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.nseindia.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User-Agent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Accept&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json, text/plain, */*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Referer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.nseindia.com/report-detail/eq_security&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="c1"&gt;// ... other headers for authentication&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;initializeSession&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Get session cookies from NSE&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;https&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/report-detail/eq_security`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extractCookies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;year&lt;/span&gt;&lt;span class="p"&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;fromDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`01-01-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;year&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`31-12-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;year&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/api/historicalOR/generateSecurityWiseHistoricalData?from=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fromDate&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;to=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;toDate&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;symbol=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;type=priceVolumeDeliverable&amp;amp;series=EQ&amp;amp;csv=true`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;makeRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&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;
  
  
  🏗️ Architecture Overview
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Backend (Node.js + Express)
&lt;/h3&gt;

&lt;p&gt;The backend handles three main responsibilities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;API Scraping Engine&lt;/strong&gt;: Direct calls to NSE APIs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Management&lt;/strong&gt;: Track multiple scraping jobs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File Management&lt;/strong&gt;: Organize and zip downloaded data
&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="c1"&gt;// Session tracking for concurrent scraping jobs&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;activeSessions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&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;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/start-scraping&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;stocks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;endYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sessionId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&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;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Initialize session tracking&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;sessionId&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="nx"&gt;stocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;endYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;startYear&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="na"&gt;completed&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;failed&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;currentStock&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;currentYear&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;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;starting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
        &lt;span class="na"&gt;startTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nx"&gt;activeSessions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Start scraping in background&lt;/span&gt;
    &lt;span class="nf"&gt;scrapingProcess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stocks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;endYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sessionId&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;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Scraping started successfully&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="nx"&gt;sessionId&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="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&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;h3&gt;
  
  
  Frontend (React + Vite)
&lt;/h3&gt;

&lt;p&gt;The frontend provides a clean interface with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stock management&lt;/strong&gt;: Add/remove stocks to scrape&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time progress&lt;/strong&gt;: Live updates during scraping&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result visualization&lt;/strong&gt;: Success/failure status for each stock&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Download functionality&lt;/strong&gt;: One-click ZIP download
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NSEScraper&lt;/span&gt; &lt;span class="o"&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;stocks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStocks&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RELIANCE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TCS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;HDFCBANK&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProgress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isRunning&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsRunning&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Real-time progress polling&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sessionId&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;isRunning&lt;/span&gt;&lt;span class="p"&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;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;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="s2"&gt;`/api/progress/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nf"&gt;setProgress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setCurrentStock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentStock&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setCurrentYear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentYear&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setCompleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&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="nf"&gt;setIsRunning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&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="mi"&gt;1000&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;clearInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;interval&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="nx"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isRunning&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"nse-scraper"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Beautiful UI components */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;
  
  
  🔧 Key Technical Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Session Management
&lt;/h3&gt;

&lt;p&gt;Each scraping job gets a unique session ID, allowing multiple users to run concurrent scraping operations without conflicts.&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;// Progress tracking endpoint&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/progress/:sessionId&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sessionId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sessionId&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;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;activeSessions&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="nx"&gt;sessionId&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&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;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Session not found&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;sessionId&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="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;failed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;currentStock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentStock&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;currentYear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentYear&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="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;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="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;100&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;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;results&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;h3&gt;
  
  
  2. Real-Time Progress Updates
&lt;/h3&gt;

&lt;p&gt;The app provides live feedback showing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Current stock being processed&lt;/li&gt;
&lt;li&gt;Current year being scraped&lt;/li&gt;
&lt;li&gt;Overall progress percentage&lt;/li&gt;
&lt;li&gt;Success/failure counts&lt;/li&gt;
&lt;li&gt;Detailed results for each operation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Intelligent Rate Limiting
&lt;/h3&gt;

&lt;p&gt;To avoid overwhelming NSE servers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1-second delay between individual requests&lt;/li&gt;
&lt;li&gt;2-second delay between different stocks&lt;/li&gt;
&lt;li&gt;Proper session initialization with cookies
&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="c1"&gt;// Add delay between requests&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&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="c1"&gt;// Longer delay between stocks&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stockIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;stocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&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="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&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;h3&gt;
  
  
  4. Automated File Organization
&lt;/h3&gt;

&lt;p&gt;Downloaded files are automatically organized and can be downloaded as a ZIP:&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/download/:sessionId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Create zip file&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;archive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;archiver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;zip&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;zlib&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="p"&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;attachment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`nse_data_&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.zip`&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;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/zip&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;archive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&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;archive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataDir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;archive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finalize&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;
  
  
  📊 Performance Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Time for 10 stocks (3 years)&lt;/th&gt;
&lt;th&gt;Reliability&lt;/th&gt;
&lt;th&gt;Resource Usage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Selenium&lt;/td&gt;
&lt;td&gt;~45 minutes&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Direct API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~4.5 minutes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;High&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Low&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  🎨 UI/UX Highlights
&lt;/h2&gt;

&lt;p&gt;The frontend features a modern, responsive design with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clean stock management&lt;/strong&gt;: Easy add/remove interface with validation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visual progress indicators&lt;/strong&gt;: Real-time progress bars and status icons&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live updates&lt;/strong&gt;: Current stock and year display without page refresh&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive design&lt;/strong&gt;: Works seamlessly on desktop and mobile&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Modern styling&lt;/strong&gt;: Clean, professional interface using Lucide React icons&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🚀 Deployment &amp;amp; Architecture
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Flexible Deployment Options
&lt;/h3&gt;

&lt;p&gt;The project supports multiple deployment strategies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single Deployment (Full-Stack)&lt;/strong&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="c1"&gt;// Serve static files only if frontend is not deployed separately&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FRONTEND_URL&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;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;frontend/dist&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;// Configure CORS based on deployment type&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;corsOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FRONTEND_URL&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; 
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FRONTEND_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:5173&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Separate Deployments&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: Railway, Render, or any Node.js hosting&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: Vercel, Netlify, or any static hosting&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Live Demo Deployment
&lt;/h3&gt;

&lt;p&gt;The live demo is hosted on Render with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic builds from GitHub&lt;/li&gt;
&lt;li&gt;Environment variable configuration&lt;/li&gt;
&lt;li&gt;Zero-downtime deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💾 Data Format &amp;amp; Quality
&lt;/h2&gt;

&lt;p&gt;Each CSV file contains comprehensive trading data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Price Data&lt;/strong&gt;: Open, High, Low, Close, Previous Close, Last Traded Price, VWAP&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Volume Data&lt;/strong&gt;: Total Traded Quantity, Total Traded Value, Number of Trades
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delivery Data&lt;/strong&gt;: Delivery Quantity, Delivery Percentage&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metadata&lt;/strong&gt;: Symbol, Series, Date, Timestamps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sample data structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Date,Symbol,Series,Open,High,Low,Close,Last,Prevclose,TOTTRDQTY,TOTTRDVAL,TIMESTAMP,TOTALTRADES,ISIN,DELIVERYQTY,DELIVERYPER
01-Jan-2024,RELIANCE,EQ,2915.00,2932.00,2901.05,2920.15,2920.15,2918.75,5234567,15234567890,01-JAN-2024,89234,INE002A01018,2617283,50.01
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🔮 Future Enhancements
&lt;/h2&gt;

&lt;p&gt;Planned improvements include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data visualization&lt;/strong&gt;: Built-in charts and analytics dashboard&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduled scraping&lt;/strong&gt;: Automated daily/weekly downloads with cron jobs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database integration&lt;/strong&gt;: Store data in PostgreSQL/MongoDB for persistence&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;REST API&lt;/strong&gt;: Additional endpoints for programmatic data access&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Export formats&lt;/strong&gt;: JSON, Excel, and direct database exports&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User authentication&lt;/strong&gt;: Personal dashboards and saved configurations&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📝 Key Lessons Learned
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;API Discovery&lt;/strong&gt;: Sometimes the best solution is finding the right API endpoint rather than scraping&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Management&lt;/strong&gt;: Proper cookie handling and headers are crucial for API access&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Experience&lt;/strong&gt;: Real-time feedback transforms the user experience&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;: Always plan for network failures and implement retry mechanisms&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Direct API calls can be orders of magnitude faster than browser automation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment Flexibility&lt;/strong&gt;: Supporting both monolithic and microservice architectures increases adoption&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  🛠️ Tech Stack Deep Dive
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Backend Technologies:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt;: Runtime environment for server-side JavaScript&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Express.js&lt;/strong&gt;: Fast, unopinionated web framework&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fs-extra&lt;/strong&gt;: Enhanced file system operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;archiver&lt;/strong&gt;: ZIP file creation for bulk downloads&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;https&lt;/strong&gt;: Native Node.js module for API calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Frontend Technologies:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React 18&lt;/strong&gt;: Modern React with hooks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vite&lt;/strong&gt;: Lightning-fast build tool and dev server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Axios&lt;/strong&gt;: Promise-based HTTP client&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lucide React&lt;/strong&gt;: Beautiful, customizable icons&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS3&lt;/strong&gt;: Modern styling with flexbox and grid&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;DevOps &amp;amp; Deployment:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Render&lt;/strong&gt;: Cloud hosting platform&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Actions&lt;/strong&gt;: CI/CD pipeline (potential future addition)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment Variables&lt;/strong&gt;: Configuration management&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🎯 Getting Started
&lt;/h2&gt;

&lt;p&gt;Ready to try it yourself?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Clone the repository&lt;/span&gt;
git clone https://github.com/singhanuj620/nse_scrap.git
&lt;span class="nb"&gt;cd &lt;/span&gt;nse_scrap

&lt;span class="c"&gt;# Install all dependencies&lt;/span&gt;
npm run install-all

&lt;span class="c"&gt;# Start development server (runs both frontend and backend)&lt;/span&gt;
npm run dev

&lt;span class="c"&gt;# Or run backend only&lt;/span&gt;
npm run server

&lt;span class="c"&gt;# Build for production&lt;/span&gt;
npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Quick Test:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Test with sample stocks&lt;/span&gt;
npm &lt;span class="nb"&gt;test&lt;/span&gt;

&lt;span class="c"&gt;# Download all configured stocks&lt;/span&gt;
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🌟 Try It Live
&lt;/h2&gt;

&lt;p&gt;Don't want to set up locally? Try the live demo:&lt;br&gt;
👉 &lt;strong&gt;&lt;a href="https://nse-scrap.onrender.com" rel="noopener noreferrer"&gt;https://nse-scrap.onrender.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Features available in the live demo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add/remove stocks from the default list&lt;/li&gt;
&lt;li&gt;Set custom date ranges&lt;/li&gt;
&lt;li&gt;Real-time progress tracking&lt;/li&gt;
&lt;li&gt;Download complete datasets as ZIP files&lt;/li&gt;
&lt;li&gt;Mobile-responsive interface&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Building this NSE scraper taught me the value of choosing the right approach over the obvious one. By leveraging direct API calls instead of browser automation, we achieved a solution that's:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;10x faster&lt;/strong&gt; than traditional scrapers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More reliable&lt;/strong&gt; with fewer points of failure&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easier to maintain&lt;/strong&gt; without UI dependency&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better user experience&lt;/strong&gt; with real-time feedback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full-stack implementation with session management and real-time progress tracking creates a professional tool that makes bulk data downloading actually enjoyable.&lt;/p&gt;

&lt;p&gt;Whether you're a quantitative analyst, researcher, or developer working with Indian stock market data, this approach can save you hours of waiting time and provide more reliable data access.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 Connect &amp;amp; Contribute
&lt;/h2&gt;

&lt;p&gt;Found this helpful? Let's connect!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;💼 &lt;strong&gt;LinkedIn&lt;/strong&gt;: &lt;a href="https://www.linkedin.com/in/anuj-singh-007/" rel="noopener noreferrer"&gt;Anuj Singh&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🐙 &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/singhanuj620" rel="noopener noreferrer"&gt;@singhanuj620&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📁 &lt;strong&gt;Project Repository&lt;/strong&gt;: &lt;a href="https://github.com/singhanuj620/nse_scrap" rel="noopener noreferrer"&gt;nse_scrap&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have suggestions, found a bug, or want to contribute? Feel free to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open an issue on GitHub&lt;/li&gt;
&lt;li&gt;Submit a pull request&lt;/li&gt;
&lt;li&gt;Connect with me on LinkedIn&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webscraping</category>
      <category>nse</category>
    </item>
    <item>
      <title>Apollo GraphQL - Setup Guide</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Sat, 06 Apr 2024 12:41:33 +0000</pubDate>
      <link>https://dev.to/singhanuj620/apollo-graphql-setup-guide-5d67</link>
      <guid>https://dev.to/singhanuj620/apollo-graphql-setup-guide-5d67</guid>
      <description>&lt;p&gt;Welcome to the world of Apollo GraphQL, where you can supercharge your JavaScript applications with efficient data fetching, state management, and more. In this technical blog, we'll dive deep into Apollo GraphQL, covering everything from its core concepts to advanced techniques.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Apollo GraphQL?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apollo GraphQL is a comprehensive GraphQL client that enables you to build robust and scalable applications by simplifying data management. It offers a range of features, including caching, state management, and tools for building UI components seamlessly with GraphQL APIs.&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%2F8d77jpik4tg98dvwuua4.png" 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%2F8d77jpik4tg98dvwuua4.png" alt="Apollo Graphql" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Getting Started&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To begin using Apollo GraphQL in your JavaScript project, you'll need to install the necessary packages:&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;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;apollo&lt;/span&gt;&lt;span class="sr"&gt;/client graphq&lt;/span&gt;&lt;span class="err"&gt;l
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, you can import the required modules in your application:&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;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createHttpLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@apollo/client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;setContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@apollo/client/link/context&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@apollo/client/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating a Client&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, you'll need to create an Apollo Client instance, specifying the URI of your GraphQL server:&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;httpLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createHttpLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:4000/graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Replace with your GraphQL server URI&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;authLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setContext&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&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;headers&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Assuming you store your token in localStorage&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;link&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;authLink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;httpLink&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InMemoryCache&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;&lt;strong&gt;Executing Queries&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that you have set up your Apollo Client, you can start executing GraphQL queries. Here's how you can fetch data using Apollo Client:&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;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
    query GetPosts {
      posts {
        id
        title
        body
      }
    }
  `&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="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="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;result&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mutations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apollo Client also supports GraphQL mutations for modifying data on the server. Here's an example of how you can perform a mutation:&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;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mutate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;mutation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
    mutation AddPost($title: String!, $body: String!) {
      addPost(title: $title, body: $body) {
        id
        title
        body
      }
    }
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New Post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This is the content of the new post.&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="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="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;result&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advanced Features&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apollo GraphQL provides several advanced features, including:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Caching&lt;/em&gt;&lt;/strong&gt;: Apollo Client automatically caches query results, reducing unnecessary network requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Local State Management&lt;/em&gt;&lt;/strong&gt;: You can manage local application state alongside remote data using Apollo Client's built-in capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pagination&lt;/em&gt;&lt;/strong&gt;: Apollo Client supports pagination out of the box, allowing you to fetch large datasets efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Error Handling&lt;/em&gt;&lt;/strong&gt;: Easily handle errors returned from GraphQL operations using Apollo Client's error handling mechanisms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this blog post, we've explored the fundamentals of Apollo GraphQL and demonstrated how to integrate it into your JavaScript applications. With its powerful features and intuitive API, Apollo GraphQL empowers developers to build modern, data-driven applications with ease. So why wait? Start leveraging the power of Apollo GraphQL in your projects today!&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>useReducer () | React Hook with project</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Wed, 14 Sep 2022 18:52:36 +0000</pubDate>
      <link>https://dev.to/singhanuj620/usereducer-react-hook-with-project-1pg</link>
      <guid>https://dev.to/singhanuj620/usereducer-react-hook-with-project-1pg</guid>
      <description>&lt;h2&gt;
  
  
  useReducerr
&lt;/h2&gt;

&lt;p&gt;A inbuilt react hook for mimicking &lt;strong&gt;Redux&lt;/strong&gt; concepts in react itself. If you are comfortable with Redux concepts, you will get the jist.&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't know about REDUX ? 🙈
&lt;/h3&gt;

&lt;h4&gt;
  
  
  ➡️➡️ Read it here &lt;a href="https://dev.to/singhanuj620/react-redux-learn-the-redux-easily-with-project-aji"&gt;Learn Redux easily with a project&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; : The code snippets or the code reference is from this Github repo, which I have made for this tutorial. It's the basic shopping cart application, that add, removes products to cart and also you can increase or decrease the product quantity.&lt;/p&gt;

&lt;p&gt;Github Repo : &lt;a href="https://github.com/singhanuj620/useReducer_tutorial" rel="noopener noreferrer"&gt;useReducer_tutorial&lt;/a&gt;&lt;br&gt;
Live Demo of the application : &lt;a href="https://singhanuj620.github.io/useReducer_tutorial/" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt;&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%2Flhw0om2220px7bzylx0y.png" 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%2Flhw0om2220px7bzylx0y.png" alt="0"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's get started 😈😈👇👇
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;An alternative to useState. Accepts a reducer of type &lt;code&gt;(state, action) =&amp;gt; newState&lt;/code&gt;, and returns the current state paired with a &lt;code&gt;dispatch&lt;/code&gt; method. (If you’re familiar with Redux, you already know how this works.)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The official definition of useReducer &lt;a href="https://reactjs.org/docs/hooks-reference.html#usereducer" rel="noopener noreferrer"&gt;Official Doc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The syntax of declaration is :&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialArg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See the main motive behind using useReducer is to have a common place known as &lt;strong&gt;store or state&lt;/strong&gt; in the application, where we can store the data that we wanted which can be accessible to the components directly. They can fetch that data from that state or update that state as required. &lt;em&gt;( There is a catch in updating the store, we will see later in the blog )&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In our shopping cart application, we have 2 main components : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Product Section&lt;/li&gt;
&lt;li&gt;Cart Section&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These both will be required to access the same state, so we will have to declare the state in their parent component, which in our case is &lt;a href="https://github.com/singhanuj620/useReducer_tutorial/blob/master/src/App.js" rel="noopener noreferrer"&gt;App.js&lt;/a&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;productReducer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./reducers&lt;/span&gt;&lt;span class="dl"&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="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;products&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
        &lt;span class="na"&gt;cart&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have declare the initial state to have 2 key value pair:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;products []&lt;/li&gt;
&lt;li&gt;cart []&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and for the reducer we are importing it from another file &lt;em&gt;( for better readability )&lt;/em&gt;.&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%2Fu09rtxx32nhd4ehez3y5.png" 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%2Fu09rtxx32nhd4ehez3y5.png" alt="1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And for the child component to access the same state, you need to pass these two i.e. state and dispatch as a prop to those child component which you want to interact with same state.&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%2Fhaknf01fk7qrv1ors3tf.png" 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%2Fhaknf01fk7qrv1ors3tf.png" alt="2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; : If you are not comfortable with this code that what's state, action, action.payload, type etc., you need to brush up redux&lt;br&gt;
concepts. More about that here : &lt;a href="https://dev.to/singhanuj620/react-redux-learn-the-redux-easily-with-project-aji"&gt;Learn Redux with&lt;br&gt;
project&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;we will be using &lt;strong&gt;dispatch&lt;/strong&gt; with specific type to update the state as per requirement. &lt;em&gt;We can only update the state using dispatch, **not directly&lt;/em&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Make sure your reducer function accepts 2 parameter i.e &lt;strong&gt;state and action&lt;/strong&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;productReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How Product component will interact with state :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/singhanuj620/useReducer_tutorial/blob/master/src/components/product/index.js" rel="noopener noreferrer"&gt;&lt;em&gt;src/components/product/index.js&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are using a dummy product API for fetching some sample products data. So from the product component, we will store the all product details to the state, so that we have access to the product list.&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;fetchProduct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;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="s1"&gt;https://dummyjson.com/products&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setProducts&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;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ADD_TO_PRODUCT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;payload&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;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;products&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;Using the dispatch, I'm updating all the product list into state. And on the basis of data present in cart [] of state, Product component is dynamically changing the button to 'add to cart' or 'remove from cart'.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Cart component will interact with state :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/singhanuj620/useReducer_tutorial/blob/master/src/components/cart/index.js" rel="noopener noreferrer"&gt;&lt;em&gt;src/components/cart/index.js&lt;/em&gt;&lt;/a&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;Cart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;cart&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we will access the state directly as shown. And if any state updating is required as changing the cart item quantity, we will use dispatch with a specific action type and payload data which will instruct the reducer to change the state as per requirement.&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;handleInc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INCREASE_QTY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleDec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DECREASE_QTY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  That's It, You have now understood what is useReducer. 😎😎
&lt;/h3&gt;

&lt;p&gt;You can play around with the github repo for more practice.&lt;br&gt;
Till then &lt;strong&gt;ADIOS&lt;/strong&gt; 🙌&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't forgot to like 💗
&lt;/h3&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JWT explained with project</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Mon, 13 Dec 2021 18:48:33 +0000</pubDate>
      <link>https://dev.to/singhanuj620/jwt-explained-with-project-37en</link>
      <guid>https://dev.to/singhanuj620/jwt-explained-with-project-37en</guid>
      <description>&lt;p&gt;&lt;a href="https://astounding-alfajores-bc2d8d.netlify.app/"&gt;My Portfolio&lt;/a&gt; || &lt;a href="https://dev.to/singhanuj620"&gt;My other blogs&lt;/a&gt; || &lt;a href="https://www.linkedin.com/in/anuj-singh-007/"&gt;Linkedin Account&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is JWT ?
&lt;/h3&gt;

&lt;p&gt;JSON Web Token (JWT) is an open standard ([RFC 7519]) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the &lt;strong&gt;HMAC&lt;/strong&gt; algorithm) or a public/private key pair using &lt;strong&gt;RSA&lt;/strong&gt; or &lt;strong&gt;ECDSA&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  When should you use JSON Web Tokens?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Authorization&lt;/li&gt;
&lt;li&gt;Information Exchange&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What is the JSON Web Token structure?
&lt;/h4&gt;

&lt;p&gt;In its compact form, JSON Web Tokens consist of three parts separated by dots (&lt;code&gt;.&lt;/code&gt;), which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Header&lt;/li&gt;
&lt;li&gt;  Payload&lt;/li&gt;
&lt;li&gt;  Signature&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, a JWT typically looks like the following.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;xxxxx.yyyyy.zzzzz&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zm_DcvZ8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn2.auth0.com/docs/media/articles/api-auth/client-credentials-grant.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zm_DcvZ8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn2.auth0.com/docs/media/articles/api-auth/client-credentials-grant.png" alt="jwt" width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://jwt.io/introduction"&gt;JWT In-Depth Knowledge&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jwt.io/#debugger-io"&gt;JWT Playground&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  To Run the application :
&lt;/h2&gt;

&lt;p&gt;You should have installed &lt;strong&gt;&lt;em&gt;&lt;a href="https://nodejs.org/en/download/"&gt;nodeJS&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://www.postman.com/downloads/"&gt;postman&lt;/a&gt;&lt;/strong&gt; and &lt;a href="https://www.mongodb.com/try/download/community"&gt;&lt;strong&gt;MongoDB&lt;/strong&gt;&lt;/a&gt; in your machine.&lt;br&gt;
We will be using postman to test our application. You can use any front-end for the same.&lt;br&gt;
Also make sure mongoDb is installed correctly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clone the project&lt;br&gt;
 &lt;code&gt;git clone https://github.com/singhanuj620/probackend_jwt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install NPM dependencies &lt;br&gt;
&lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the server &lt;br&gt;
&lt;code&gt;npm run start&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Register a User first. &lt;br&gt;
&lt;code&gt;http://localhost:4000/register&lt;/code&gt;&lt;br&gt;
to register a user. Format will be as follows : &lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fj1kg0yx6nk1beihwevjp.png" 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%2Fj1kg0yx6nk1beihwevjp.png" alt="register" width="800" height="243"&gt;&lt;/a&gt;&lt;br&gt;
Congratulations !!! User is successfully saved in database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login with existing user to check jwt working 
&lt;code&gt;http://localhost:4000/login&lt;/code&gt;
to logina user. Format will be as follows : &lt;/li&gt;
&lt;/ul&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%2Fi3iumggljuzzpy4jmj4c.png" 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%2Fi3iumggljuzzpy4jmj4c.png" alt="login" width="800" height="240"&gt;&lt;/a&gt;&lt;br&gt;
Congratulations !!! User is successfully logged into application.&lt;/p&gt;

&lt;p&gt;You can now access the &lt;strong&gt;SECRET ROUTE&lt;/strong&gt; &lt;code&gt;http://localhost:4000/dashboard&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since we have done with using the application, Now let's understand how &lt;strong&gt;JWT&lt;/strong&gt; is working in background. 🙌🙌🙌&lt;/p&gt;
&lt;h2&gt;
  
  
  Working of JWT in this application
&lt;/h2&gt;

&lt;p&gt;We are using a popular jwt library for encoding and decoding of token. For more info visit &lt;a href="https://www.npmjs.com/package/jsonwebtoken"&gt;JWT NPMJS&lt;/a&gt;&lt;br&gt;
And to encrypt the password we are using &lt;a href="https://www.npmjs.com/package/bcryptjs"&gt;bCryptJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will be using jwt in this flow :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First user is registered into database&lt;/li&gt;
&lt;li&gt;User is going to login, and that's where a &lt;strong&gt;new&lt;/strong&gt; token is generated specific for this user&lt;/li&gt;
&lt;li&gt;This genrated token is saved into cookies, so that accessing the SECRET route, this jwt token is checked for the confirmation.&lt;/li&gt;
&lt;li&gt;BINGOOOOOOO !!!!&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  When User is going to login
&lt;/h3&gt;

&lt;p&gt;We are going to find the user from database and validate password using bCryptJS, and is everything is okay, then we are going to generate a new token using the jsonwebtoken library.&lt;/p&gt;

&lt;p&gt;It has 3 parameters : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;what data you want to encode in this token, here i want to encode an object having 2 key i.e user_id and email.&lt;/li&gt;
&lt;li&gt;A secret key which can be any random string&lt;/li&gt;
&lt;li&gt;Time when this token is going to expires, in this case i have allocated 2 hour lifespan of this token.
&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;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;user_id&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;_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SECRET_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;expiresIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2h&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;and then pass/save this token into cookies to front-end. We are using &lt;a href="https://www.npmjs.com/package/cookie-parser"&gt;cookie-parser&lt;/a&gt; npm library to do this work.&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;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="k"&gt;new&lt;/span&gt;  &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&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;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="kc"&gt;true&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;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&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;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;token&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Okay so now user is logged in, but how should be validate that the token which is generated is authorized user and he/she is requesting to access the SECRET route is allowed ? 🙄🙄🙄
&lt;/h4&gt;

&lt;h3&gt;
  
  
  Validating JWT token 💥💥💥
&lt;/h3&gt;

&lt;p&gt;When logged in user tries to access the SECRET route i.e in our case &lt;code&gt;/dashboard&lt;/code&gt; then, a middleware &lt;strong&gt;&lt;em&gt;auth&lt;/em&gt;&lt;/strong&gt; is going to validate the token.&lt;/p&gt;

&lt;p&gt;For that backend has to fetch the token which is set in cookies when user was login.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt; For those who don't know what's middleware. &lt;strong&gt;Middleware&lt;/strong&gt; is just a check between 2 item. If check is okay, proceed to next operation, otherwise return back from there. Imagine it just like &lt;em&gt;watchman&lt;/em&gt; 😂.&lt;/p&gt;

&lt;p&gt;Everytime when anyone tries to access the &lt;strong&gt;&lt;em&gt;SECRET&lt;/em&gt;&lt;/strong&gt; route, this &lt;strong&gt;auth&lt;/strong&gt; middleware will check that if that request has token in cookie or not (only logged in user will have token in cookie). If not, return back.&lt;/p&gt;

&lt;p&gt;If token is there in cookie, it will check that token is authentic or not.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;HOW&lt;/em&gt;&lt;/strong&gt; ? 🙄🙄&lt;br&gt;
Remember that secret key which was just a random string, yes that will help to decode the token and fetch the data which was encoded into token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;WHICH DATA&lt;/em&gt;&lt;/strong&gt;? 🙄🙄&lt;br&gt;
Remember user_id and email 😉😉&lt;/p&gt;

&lt;p&gt;And if everything is good, proceed to the next operation 💯&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;try&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;decode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SECRET_KEY&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&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;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid Token&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="k"&gt;return&lt;/span&gt;  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What we have learned ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What are JWT&lt;/li&gt;
&lt;li&gt;How to run this github repo application&lt;/li&gt;
&lt;li&gt;How to genrate JWT token&lt;/li&gt;
&lt;li&gt;How to validate JWT Token&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Thank You 🤗 💥🤩
&lt;/h2&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Redux | Learn the redux easily with project</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Mon, 05 Jul 2021 10:23:00 +0000</pubDate>
      <link>https://dev.to/singhanuj620/react-redux-learn-the-redux-easily-with-project-aji</link>
      <guid>https://dev.to/singhanuj620/react-redux-learn-the-redux-easily-with-project-aji</guid>
      <description>&lt;h1&gt;
  
  
  💥💥 React Redux Example 💥💥
&lt;/h1&gt;

&lt;h4&gt;
  
  
  This is a &lt;em&gt;todo&lt;/em&gt; project for understanding the concepts of redux in react, this &lt;a href="https://github.com/singhanuj620/todo_redux"&gt;&lt;strong&gt;github project&lt;/strong&gt;&lt;/a&gt; is referenced in this project
&lt;/h4&gt;

&lt;h2&gt;
  
  
  What is Redux ?
&lt;/h2&gt;

&lt;p&gt;Redux is used for &lt;strong&gt;state management&lt;/strong&gt; for the application. It's main advantage is to overcome the problem of "props drilling" among the components.&lt;/p&gt;

&lt;p&gt;For example, Let's assume we have 4 component named A,B,C,D and their representation is like :&lt;br&gt;
A ( Parent Component )&lt;br&gt;
|&lt;br&gt;
B&lt;br&gt;
|&lt;br&gt;
C&lt;br&gt;
|&lt;br&gt;
D ( Leaf Component )&lt;/p&gt;

&lt;p&gt;and we have a prop named &lt;strong&gt;&lt;em&gt;itemCode&lt;/em&gt;&lt;/strong&gt; which is generated at component &lt;strong&gt;A&lt;/strong&gt;, and only to be used at component &lt;strong&gt;D&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;&lt;code&gt;Traditional Way&lt;/code&gt;&lt;/strong&gt; was to pass that itemCode as an prop to &lt;strong&gt;B&lt;/strong&gt;, then &lt;strong&gt;C&lt;/strong&gt;, and at last to &lt;strong&gt;D&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;😎😎 How Redux Solves&lt;/code&gt;&lt;/strong&gt; is that it makes an store for an application, which holds all the states of application at one place. So when itemCode is generated at component &lt;strong&gt;A&lt;/strong&gt;, insted of passing it as an props to all the way down to component &lt;strong&gt;D&lt;/strong&gt;, component &lt;strong&gt;A&lt;/strong&gt; will store that itemCode in the &lt;strong&gt;Store&lt;/strong&gt;, and component &lt;strong&gt;D&lt;/strong&gt; will fetch itemCode value form that &lt;strong&gt;Store&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;, But what's the problem in &lt;strong&gt;props&lt;/strong&gt; 🙄🙄 ?&lt;br&gt;
This todo application is very small scale project, in large projects, this props count be large like 10, 20, 100 anything, so using props everywhere will be make the application very very complex 🤯🤯🤯&lt;/p&gt;
&lt;h3&gt;
  
  
  Let's drive deep into working of Redux
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;First let's setup the basic project&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt; Create new react project &lt;code&gt;npx create-react-app todo_redux&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Install redux dependencies &lt;code&gt;npm install react-redux redux&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Make an folder named &lt;strong&gt;&lt;em&gt;action&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;reducer&lt;/em&gt;&lt;/strong&gt; in &lt;code&gt;/src&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Inside &lt;strong&gt;action&lt;/strong&gt; folder, make 2 files, &lt;code&gt;/action-types.js&lt;/code&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;code&gt;/todo.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Inside &lt;strong&gt;reducer&lt;/strong&gt; folder, make file named &lt;code&gt;/todo.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; And in &lt;strong&gt;&lt;em&gt;/src&lt;/em&gt;&lt;/strong&gt; folder a file, make a file named &lt;code&gt;store.js&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this your project heirarchy will look like :&lt;br&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%2Fmxmar6d06qxsq9h9iitw.png" 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%2Fmxmar6d06qxsq9h9iitw.png" alt="Alt Text" width="292" height="765"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  But what are these Action, Reducer, and Store ?
&lt;/h2&gt;
&lt;h1&gt;
  
  
  💥💥 Actions 💥💥 :
&lt;/h1&gt;

&lt;p&gt;It contains the logic that will tell &lt;strong&gt;Reducer&lt;/strong&gt; &lt;code&gt;what should be done&lt;/code&gt; on calling specific commands which developer has made. Like in our case, their are 2 action which is made,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Add Todo&lt;/li&gt;
&lt;li&gt; Remove Todo&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, &lt;em&gt;Action will tell Reducer&lt;/em&gt; that, Okay so there is an call from component to Add Todo, So Hey Reducer, we now have to Add an todo with this that details.&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax for Action :
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ADD_TODO&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./action-types&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todo&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ADD_TODO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;todo&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;&lt;strong&gt;addTodo&lt;/strong&gt; is a name of the package which return object with a compulsory field *&lt;strong&gt;*"type"**&lt;/strong&gt; and optional field &lt;strong&gt;"payload"&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Type&lt;/strong&gt; : It is used to validate action on reducer side that okay an action of type blah blah 😜 type is recieved and I have to perform logic related to this blah blah 🙈 only&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Payload&lt;/strong&gt; : Sometimes on the reducer side, some data is sent which is used to update the state in the store.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  💥💥 Reducer 💥💥 :
&lt;/h1&gt;

&lt;p&gt;So till now we have an action which states what to do, but &lt;code&gt;how to do ?&lt;/code&gt; is defined in reducer file. &lt;em&gt;For our case,&lt;/em&gt; what to do with the state/store when an addTodo action is recieved == We have to add an todo with details recieved from action package into out store which has some previous todos and return the updated state of todos in out store.&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax for Reducer
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ADD_TODO&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../action/action-types&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;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="na"&gt;ADD_TODO&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="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&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;See here the &lt;strong&gt;&lt;em&gt;types field of action&lt;/em&gt;&lt;/strong&gt; comes into play, to validate what logic is to be performed when an certain type of action is called. And &lt;strong&gt;&lt;em&gt;payload data&lt;/em&gt;&lt;/strong&gt; to update the state/store.&lt;/p&gt;

&lt;p&gt;There can be many files containing multiple reducers, but at the end we will combine all the reducers from all the files into one &lt;strong&gt;root reducer&lt;/strong&gt;, because the store expects only one reducer. &lt;em&gt;( we will see how to do that later in this article )&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  💥💥 Store 💥💥 :
&lt;/h1&gt;

&lt;p&gt;Store is the place where all the states of an application is kept. &lt;strong&gt;Store is readonly&lt;/strong&gt; , &lt;strong&gt;for updating, we can only do it through reducer&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;And also, for an whole application, there will be only 1 store.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax for Store
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;combineReducers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./reducer/todo&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;rootReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;combineReducers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;todos&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;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rootReducer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt;  &lt;span class="k"&gt;default&lt;/span&gt;  &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here we import all the reducer file and with the help of &lt;code&gt;combineReducers&lt;/code&gt; we combine them into 1 reducer and with &lt;code&gt;createStore&lt;/code&gt; we create an store for the application.&lt;/p&gt;
&lt;h3&gt;
  
  
  So till now we have made an &lt;code&gt;Store&lt;/code&gt; with root reducers combining all the reducers, &lt;code&gt;Action&lt;/code&gt; which tells what to do and &lt;code&gt;Reducer&lt;/code&gt; which tells how to do. Now the question is how to access store from component ? 🤷‍♀️🤷‍♀️🤷‍♀️
&lt;/h3&gt;

&lt;p&gt;Firstly we have to wrap the main parent component &lt;strong&gt;&lt;em&gt;inside App.js&lt;/em&gt;&lt;/strong&gt; with&lt;br&gt;
&lt;code&gt;&amp;lt;Provider store={store}&amp;gt; all the components comes here &amp;lt;/Provider &amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Provider&lt;/strong&gt; is &lt;code&gt;react-redux&lt;/code&gt; magic which handles all the work and &lt;strong&gt;store&lt;/strong&gt; is passed it, which is imported from &lt;em&gt;store file&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Now connecting component to store ✌✌ :
&lt;/h3&gt;

&lt;p&gt;We have to use 2 function which will fetch and sent the data to store through action then reducers all that flow.&lt;/p&gt;

&lt;p&gt;Introducing :&lt;/p&gt;
&lt;h1&gt;
  
  
  mapStateToProps( ) 🤑🤑:
&lt;/h1&gt;

&lt;p&gt;This function is used to fetch the data from store and pass it as a prop to the component, and from then onwards in the component it is used as traditional way like using value from props.&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax for mapStateToProps()
&lt;/h3&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;mapStateToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&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="na"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;todos&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;and in component, it will be accessible as props&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;TodoForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;todos&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  mapDispatchToProps ( ) 😁😁:
&lt;/h1&gt;

&lt;p&gt;This function is used to prepare action package which will later on go to reducer to update the state of the application. For example in our case, we have to add todo with todo detail so we have to prepare action of type addtodo&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax for mapDispatchToProps ()
&lt;/h3&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;mapDispatchToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dispatch&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="na"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todo&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="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todo&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;and in component, it will be accessible as props&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;TodoForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;addTodo&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  All Done 🙌🎉🎉
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Thank You for reading it 🤗🤗 Hope you like it.
&lt;/h2&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>redux</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mongoose "Populate()" in most simple way | How to import a collection into another schema in Mongodb</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Sun, 18 Apr 2021 10:55:37 +0000</pubDate>
      <link>https://dev.to/singhanuj620/mongoose-populate-in-most-simple-way-how-to-import-a-collection-into-another-schema-in-mongodb-4nnf</link>
      <guid>https://dev.to/singhanuj620/mongoose-populate-in-most-simple-way-how-to-import-a-collection-into-another-schema-in-mongodb-4nnf</guid>
      <description>&lt;p&gt;Hello everyone, I'm going to demenstrate and explain the confusing topic of &lt;strong&gt;Mongodb&lt;/strong&gt;/&lt;strong&gt;Mongoose&lt;/strong&gt; that is &lt;strong&gt;"Populate( )"&lt;/strong&gt; function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement :
&lt;/h2&gt;

&lt;p&gt;Suppose you have 2 schema model named :&lt;br&gt;
1 - Address Model&lt;br&gt;
2 - User Model&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Address Model&lt;/strong&gt;:&lt;br&gt;
There are 3 attributes in this i.e &lt;em&gt;pincode&lt;/em&gt;, &lt;em&gt;state&lt;/em&gt;, &lt;em&gt;address&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
const  mongoose = require("mongoose");
const  Schema = mongoose.Schema;

const  addressSchema = new  Schema({
    address:  String,
    state:  String,
    pincode : Number
});

const  Address= mongoose.model("address", addressSchema);
module.exports = Address;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;User Model&lt;/strong&gt;:&lt;br&gt;
There are 3 attributes in this i.e &lt;em&gt;name&lt;/em&gt;, &lt;strong&gt;address&lt;/strong&gt;, and designation.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
const  mongoose = require("mongoose");
const  Schema = mongoose.Schema;
const {ObjectId} = mongoose.Schema; 

const  userSchema = new  Schema({
    name:  String,
    designation:  String,
    address: {
        type :  ObjectId,
        ref :  "address"
    }
});

const  User = mongoose.model("user", userSchema);
module.exports = User;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Solution :
&lt;/h2&gt;

&lt;p&gt;Can you see the modification in &lt;strong&gt;User Model&lt;/strong&gt; ?&lt;br&gt;
The addition of :&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
address: {
        type :  ObjectId,
        ref :  "address"
    }


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

&lt;/div&gt;

&lt;p&gt;makes all the changes here. &lt;/p&gt;

&lt;p&gt;We are here not making the entry in &lt;em&gt;User Model&lt;/em&gt;'s &lt;strong&gt;address&lt;/strong&gt; section but instead using &lt;strong&gt;address&lt;/strong&gt; model to store the data and uses it's &lt;em&gt;__id&lt;/em&gt;_ in &lt;em&gt;User Model&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;And at time of fetching the data from &lt;strong&gt;User Model&lt;/strong&gt; we will &lt;strong&gt;POPULATE&lt;/strong&gt; the &lt;em&gt;address&lt;/em&gt; attribute from the &lt;strong&gt;Address Model&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Object Id ?
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
const {ObjectId} = mongoose.Schema; 


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

&lt;/div&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
type :  ObjectId,


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

&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;ObjectId&lt;/strong&gt; is the one of the &lt;em&gt;data types&lt;/em&gt; of Mongoose, that tells the mongoose that this &lt;strong&gt;is referenced&lt;/strong&gt; to another &lt;strong&gt;collection&lt;/strong&gt; in &lt;em&gt;MongoDb Database&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After &lt;strong&gt;importing&lt;/strong&gt;, it is used along with &lt;strong&gt;ref&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ref  ?
&lt;/h2&gt;

&lt;p&gt;Now, &lt;strong&gt;ObjectId&lt;/strong&gt; is used along with &lt;strong&gt;ref&lt;/strong&gt;. &lt;br&gt;
&lt;strong&gt;Ref&lt;/strong&gt; tells the &lt;em&gt;Mongoose&lt;/em&gt; that in which &lt;strong&gt;Collection&lt;/strong&gt; the importing data is &lt;strong&gt;present&lt;/strong&gt;. In our case, it's the &lt;em&gt;Address Model&lt;/em&gt;_ that is being imported and used in the &lt;em&gt;User Model&lt;/em&gt;. So,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
address: {
        type :  ObjectId,
        ref :  "address"
    }


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; : The &lt;strong&gt;value&lt;/strong&gt; in &lt;em&gt;ref&lt;/em&gt; the same as the &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
const  Address= mongoose.model("address", addressSchema);


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

&lt;/div&gt;

&lt;p&gt;in &lt;em&gt;Address Model&lt;/em&gt;_.&lt;/p&gt;

&lt;h2&gt;
  
  
  At last using POPULATE ( )
&lt;/h2&gt;

&lt;p&gt;So, now it's time to fetch the data from the &lt;strong&gt;User Model&lt;/strong&gt; and at time of fetching, filling the &lt;strong&gt;address&lt;/strong&gt; attribute of &lt;em&gt;User Model&lt;/em&gt; with data from the &lt;em&gt;Address Model&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let's suppose, &lt;br&gt;
the &lt;em&gt;__id&lt;/em&gt;_ of data in &lt;strong&gt;address model&lt;/strong&gt; is &lt;strong&gt;100&lt;/strong&gt;.&lt;br&gt;
So, at &lt;strong&gt;time of entering&lt;/strong&gt; data into &lt;strong&gt;User Model&lt;/strong&gt;, pass the &lt;em&gt;__id&lt;/em&gt;_ i.e &lt;em&gt;100&lt;/em&gt; to the &lt;strong&gt;address attribute&lt;/strong&gt; of &lt;em&gt;User Model&lt;/em&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
User.find({}).populate("address").exec((err, result) =&amp;gt; {
    if(err){
        return  res.json({error :  err})
    }
    res.json({result :  result})
    });


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

&lt;/div&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%2Fozxvr1f8bby3un9t9xch.png" 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%2Fozxvr1f8bby3un9t9xch.png" alt="Mongoose Populate"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.populate("address")&lt;/strong&gt; will fill the data coming from &lt;strong&gt;User.find({})&lt;/strong&gt; and find the &lt;em&gt;__id&lt;/em&gt;_ present in (in our case &lt;em&gt;__id&lt;/em&gt;_ is 100), and find that in &lt;strong&gt;Address Model&lt;/strong&gt; and take that data and fill into &lt;strong&gt;User Model&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You
&lt;/h2&gt;

&lt;p&gt;Thank you, for being patient and reading till last, Hope you find it usefull. 🙂🙂🙂&lt;/p&gt;

&lt;p&gt;My &lt;strong&gt;Portfolio&lt;/strong&gt; : &lt;a href="https://anujportfolio.herokuapp.com/" rel="noopener noreferrer"&gt;https://anujportfolio.herokuapp.com/&lt;/a&gt;&lt;br&gt;
My &lt;strong&gt;Github&lt;/strong&gt; : &lt;a href="https://github.com/singhanuj620" rel="noopener noreferrer"&gt;https://github.com/singhanuj620&lt;/a&gt;&lt;br&gt;
My &lt;strong&gt;Linkedin&lt;/strong&gt; : &lt;a href="https://www.linkedin.com/in/anuj-singh-007/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/anuj-singh-007/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback is always welcomed. 🤗🤗&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>mongoose</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to fix nodemon error- nodemon.ps1 cannot be loaded because running scripts is disabled on this system</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Fri, 19 Mar 2021 13:18:11 +0000</pubDate>
      <link>https://dev.to/singhanuj620/how-to-fix-nodemon-error-nodemon-ps1-cannot-be-loaded-because-running-scripts-is-disabled-on-this-system-1dc3</link>
      <guid>https://dev.to/singhanuj620/how-to-fix-nodemon-error-nodemon-ps1-cannot-be-loaded-because-running-scripts-is-disabled-on-this-system-1dc3</guid>
      <description>&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%2Fp2dlh8nr2dxzxmg4ya6q.png" 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%2Fp2dlh8nr2dxzxmg4ya6q.png" alt="Error_Img"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem here is with &lt;em&gt;"Get-ExecutionPolicy"&lt;/em&gt; value is &lt;em&gt;Restricted&lt;/em&gt;. We have to change it to &lt;em&gt;Unrestricted&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1&lt;/em&gt;&lt;br&gt;
Open Windows PowerShell with Run As Administrator&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 2&lt;/em&gt;&lt;br&gt;
Execute the following command&lt;/p&gt;

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

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

&lt;/div&gt;

&lt;p&gt;The result you will see is &lt;em&gt;Restricted&lt;/em&gt;&lt;br&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%2Fldtvxwzrci1hgo40r743.png" 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%2Fldtvxwzrci1hgo40r743.png" alt="1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 3&lt;/em&gt;&lt;br&gt;
Execute the following command&lt;/p&gt;

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

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

&lt;/div&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%2Fwk9d27wze8mxqe60f8gk.png" 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%2Fwk9d27wze8mxqe60f8gk.png" alt="2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Done&lt;/em&gt;&lt;br&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%2Fjtgz77svcp3jnymub7rw.png" 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%2Fjtgz77svcp3jnymub7rw.png" alt="3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and it's fixed 🤗🤗🤗🤗&lt;br&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%2Fcjar48g41y48rvgurl6o.png" 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%2Fcjar48g41y48rvgurl6o.png" alt="4"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>nodemon</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to scroll to the top while using react-router-dom</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Sun, 07 Mar 2021 17:49:11 +0000</pubDate>
      <link>https://dev.to/singhanuj620/how-to-scroll-to-the-top-while-using-react-router-dom-30nd</link>
      <guid>https://dev.to/singhanuj620/how-to-scroll-to-the-top-while-using-react-router-dom-30nd</guid>
      <description>&lt;p&gt;Hey ✌✌&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PROBLEM TO BE SOLVED&lt;/strong&gt; 🤷‍♀️🤷‍♀️🤷‍♀️🤷‍♀️🤷‍♀️: &lt;/p&gt;

&lt;p&gt;When we use &lt;strong&gt;react-router-dom&lt;/strong&gt; &lt;em&gt;library&lt;/em&gt; for routing pages and links in the react project, the problem with it is that when clicked on an &lt;em&gt;Link&lt;/em&gt; the next component rendered does not get started from the &lt;strong&gt;top&lt;/strong&gt; of the page, instead it renders the page from the scroll height of the parent component i.e the component which holds the &lt;em&gt;Link&lt;/em&gt; tag.&lt;/p&gt;

&lt;p&gt;So, what we are going to do is to render the new component/page/route from &lt;strong&gt;top&lt;/strong&gt; of the scroll height, not from in-between.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SOLUTION&lt;/strong&gt; 😎😎😎😎 : &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Make a new File just like other component file&lt;/em&gt; - Let us name it &lt;strong&gt;ScrollToTop.js&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;import React, { Component } from "react";
import { withRouter } from "react-router-dom";
class ScrollToTop extends Component {
  componentDidUpdate(prevProps) {
    if (this.props.location !== prevProps.location) {
      window.scrollTo(0, 0);
    }
  }
  render() {
    return &amp;lt;React.Fragment /&amp;gt;;
  }
}
export default withRouter(ScrollToTop); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add this file as a normal component to just below the &lt;strong&gt;&lt;/strong&gt; tag like this :&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%2Fqldludztapdrejy47xvy.png" 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%2Fqldludztapdrejy47xvy.png" alt="Screenshot" width="625" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>router</category>
      <category>dom</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How Google is competing against Facebook, Twitter, and Linkedin in marketing space? #PeopleCard</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Wed, 12 Aug 2020 14:08:22 +0000</pubDate>
      <link>https://dev.to/singhanuj620/how-google-is-competing-against-facebook-twitter-and-linkedin-in-marketing-space-peoplecard-4kdh</link>
      <guid>https://dev.to/singhanuj620/how-google-is-competing-against-facebook-twitter-and-linkedin-in-marketing-space-peoplecard-4kdh</guid>
      <description>&lt;p&gt;In social media advertising, some big giants are Facebook, Twitter, and Linkedin because of their way to collect the user's information.&lt;/p&gt;

&lt;p&gt;Facebook and Twitter being somewhat gathering informal data about people and Linkedin on the other hand collecting formal aspects of data about people.&lt;/p&gt;

&lt;p&gt;In this whole scenario, Google was missing out somewhere. It tried to do the same with Google+, but failed miserably.&lt;/p&gt;

&lt;p&gt;But now it has used the biggest weapon it has i.e 🔥 SEARCH ENGINE 🔥 .&lt;/p&gt;

&lt;p&gt;By the announcement of 🔥 People's Card 🔥 , Google is also getting into a social media advertising club.&lt;/p&gt;

&lt;p&gt;Who all have made one for themselves or going to make? Do share it in comments. !!!&lt;/p&gt;

&lt;p&gt;☺☺☺☺☺&lt;/p&gt;

</description>
      <category>database</category>
    </item>
    <item>
      <title>UrlShortner using Nodejs and MongoDb | Node.js Project | Javascript</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Fri, 03 Jul 2020 05:47:55 +0000</pubDate>
      <link>https://dev.to/singhanuj620/urlshortner-using-nodejs-and-mongodb-25ec</link>
      <guid>https://dev.to/singhanuj620/urlshortner-using-nodejs-and-mongodb-25ec</guid>
      <description>&lt;p&gt;Hello everyone, I'm &lt;strong&gt;&lt;code&gt;Anuj Singh&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Description about the project
&lt;/h2&gt;

&lt;p&gt;In this post, I am going to show how you can make a URL shortener web application that shorts the provided full URL into short URL and also keeps a count on how many times that short URL has been clicked.&lt;/p&gt;

&lt;p&gt;We will be using the following stack for this :&lt;/p&gt;

&lt;p&gt;For FrontEnd - &lt;code&gt;HTML5 and CSS3 + Javascript&lt;/code&gt;&lt;br&gt;
For Backend  - &lt;code&gt;NodeJs&lt;/code&gt;&lt;br&gt;
For Database - &lt;code&gt;MongoDB&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's start
&lt;/h1&gt;
&lt;h3&gt;
  
  
  Prerequisites :
&lt;/h3&gt;

&lt;p&gt;1 : Install &lt;a href="https://nodejs.org/en/download/"&gt;NodeJs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 : Install &lt;a href="https://www.mongodb.com/download-center/community"&gt;MongoDb&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Making The Folder Directory -
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt; - &lt;code&gt;Don't Make the node_modules, package.json and package-lock.jsn file now, it will be addressed afterward.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;.gitignore&lt;/strong&gt; file, write "node_modules". That's it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qQjNlsQ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/SthBUzM.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qQjNlsQ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/SthBUzM.jpg" alt="Folder Directory" width="314" height="444"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Files Used are -
&lt;/h3&gt;

&lt;p&gt;1 : &lt;strong&gt;&lt;code&gt;index.js&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
   Starting Point to the Project, aka app.js&lt;br&gt;
2 : &lt;strong&gt;&lt;code&gt;shortUrl.js&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
   MongoDb schema for the project&lt;br&gt;
3 : &lt;strong&gt;&lt;code&gt;home.ejs&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
   The HTML code wrapped in &lt;em&gt;ejs&lt;/em&gt; for dynamic HTML&lt;/p&gt;

&lt;p&gt;Now open VSCode (or your own code editor) and open the terminal in the main folder after creating all those files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Run &lt;em&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;/em&gt;, and fill the corresponding fields like :&lt;br&gt;
(app.js) - index.js&lt;br&gt;
(author) - your name&lt;br&gt;
and yes yes enter enter in other. Even in &lt;em&gt;License&lt;/em&gt; tap enter for default entry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Update&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
So by now, you have &lt;em&gt;package.json&lt;/em&gt; and &lt;em&gt;package-lock.json&lt;/em&gt; file in your directory.&lt;/p&gt;

&lt;p&gt;Now in &lt;em&gt;command terminal&lt;/em&gt; type - &lt;br&gt;
&lt;strong&gt;&lt;code&gt;npm install --save ejs express mongoose shortid nodemon&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This will install the following npm package that will be used in creating and running of this project i.e &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;ExpressJs&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;code&gt;ShortId&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;code&gt;Ejs&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;code&gt;Mongoose&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;code&gt;Nodemon&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;(&lt;strong&gt;P.S&lt;/strong&gt; I'm not going in detail of these. You have &lt;em&gt;Google&lt;/em&gt; use it)&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;Schema i.e shortUrl.js&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');
const shortId = require('shortid');


const shortUrlSchema = new mongoose.Schema({
    full:{
        type: String,
        required: true
    },
    short:{
        type: String,
        required: true,
        default: shortId.generate
    },
    clicks:{
        type:Number,
        required: true,
        default: 0
    }
});

module.exports = mongoose.model('ShortUrl',shortUrlSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this file, there are 3 sections.&lt;br&gt;
&lt;code&gt;Full&lt;/code&gt;: That stores actual URL&lt;br&gt;
&lt;code&gt;Short&lt;/code&gt;: That stores an unique short id generated by shortid library.&lt;br&gt;
&lt;code&gt;Clicks&lt;/code&gt;: That stores integer value of number of clicks.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;home.ejs&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"&amp;gt;
    &amp;lt;title&amp;gt;URL SHORTNER&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;h1&amp;gt;Shrink URL&amp;lt;/h1&amp;gt;
        &amp;lt;form action="/shortUrl" method="POST" class="my-4 form-inline"&amp;gt;
            &amp;lt;label for="fullUrl" class="sr-only"&amp;gt;Enter Full Url&amp;lt;/label&amp;gt;
            &amp;lt;input type="text" required placeholder="Enter Here" name="fullUrl" id="fullUrl" class="form-control mr-2" style="width: 80%;"&amp;gt;
            &amp;lt;button type="submit" class="btn btn-md btn-success"&amp;gt;Shrink It !!&amp;lt;/button&amp;gt;
        &amp;lt;/form&amp;gt;

        &amp;lt;table class="table table-striped"&amp;gt;
            &amp;lt;thead&amp;gt;
                &amp;lt;tr&amp;gt;
                    &amp;lt;th&amp;gt;Full Url&amp;lt;/th&amp;gt;
                    &amp;lt;th&amp;gt;Shrinked Url&amp;lt;/th&amp;gt;
                    &amp;lt;th&amp;gt;Clicked&amp;lt;/th&amp;gt;
                &amp;lt;/tr&amp;gt;
            &amp;lt;/thead&amp;gt;
            &amp;lt;tbody&amp;gt;
                &amp;lt;% shortUrls.forEach(shortUrl =&amp;gt; { %&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;td&amp;gt;&amp;lt;a href="&amp;lt;%=shortUrl.full%&amp;gt;"&amp;gt;&amp;lt;%=shortUrl.full%&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;
                        &amp;lt;td&amp;gt;&amp;lt;a href="&amp;lt;%=shortUrl.short%&amp;gt;"&amp;gt;&amp;lt;%=shortUrl.short%&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;
                        &amp;lt;td&amp;gt;&amp;lt;%=shortUrl.clicks%&amp;gt;&amp;lt;/td&amp;gt;
                    &amp;lt;/tr&amp;gt;
                &amp;lt;% }) %&amp;gt;
            &amp;lt;/tbody&amp;gt;
        &amp;lt;/table&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;


&lt;p&gt;This is the frontend of the application, where the data is presented visually in table format. &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%2Fi%2F4fa9tlnhfk2gw9pkxunc.png" 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%2Fi%2F4fa9tlnhfk2gw9pkxunc.png" alt="Home.ejs" width="800" height="363"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;Index.js&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const mongoose = require('mongoose');
const ShortUrl = require('./models/shortUrl');
const app = express();


mongoose.connect("&amp;lt;Enter your database connection url here&amp;gt;", {useNewUrlParser: true , 
useUnifiedTopology: true});

app.set('view engine' , 'ejs');
app.use(express.urlencoded({extended: false}));

app.get('/',async (req,res) =&amp;gt; {
    const shortUrls = await ShortUrl.find()
    res.render('home',{shortUrls: shortUrls});
});

app.post('/shortUrl', async (req,res) =&amp;gt; {
    await ShortUrl.create({full:req.body.fullUrl})
    res.redirect("/");
});

app.get('/:shortUrl', async (req,res) =&amp;gt; {
    const shortUrl = await ShortUrl.findOne({short: req.params.shortUrl})
    if(shortUrl == null){
        res.sendStatus(404)
    }
    shortUrl.clicks++;
    shortUrl.save();
    res.redirect(shortUrl.full)
})

app.listen(process.env.PORT || 3000);

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

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; &lt;code&gt;Write your own DB connection url in mongoose.connect()&lt;/code&gt;&lt;br&gt;
Here on the submission of the data from the home.ejs page, the actual URL is stored in DB with a random unique shortid associated with it, and default clicks is 0. When someone clicks on the short URL, the shortUrl id is searched in the DB and coresponding actual id is returned back, also increasing the click by 1.&lt;/p&gt;
&lt;h1&gt;
  
  
  THANK YOU !!!
&lt;/h1&gt;
&lt;h2&gt;
  
  
  &lt;code&gt;Follow for more such stuff&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Instagram : https://instagram.com/anujcodeop&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Portfolio : https://anujportfolio.herokuapp.com&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/singhanuj620"&gt;
        singhanuj620
      &lt;/a&gt; / &lt;a href="https://github.com/singhanuj620/urlShortner"&gt;
        urlShortner
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Web Application made with nodejs and mongoDb that shorts the full url and tracks the number of times it is clicked.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;urlShortner&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;Web Application made with nodejs and mongoDb that shorts the full url and tracks the number of times it is clicked.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;&lt;a href="http://urlshortneranuj.herokuapp.com/" rel="nofollow"&gt;LIVE DEMO&lt;/a&gt;&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Please give it a start too. Thanks !&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How to Use it -&amp;gt;&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Note - Make Sure you have nodejs and mongoDb installed in the system.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt; : For running it very first time, run &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; : Open 'cmd' as an administrator, and type &lt;code&gt; net start mongoDb&lt;/code&gt; for starting the mongoDb database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt; : In folder terminal, to start the project run &lt;code&gt;npm run devStart&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt; : Now open '&lt;a href="https://localhost:3000" rel="nofollow"&gt;https://localhost:3000&lt;/a&gt;' in your web browser to use the project.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt; : After using, open again 'cmd' as an administrator, and type 'net stop mongoDb' for stoping the mongoDb database.&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/singhanuj620/urlShortner"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>node</category>
      <category>npm</category>
      <category>mongodb</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Can I Use 'Variables' in CSS ? Yes !! Let's see how</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Fri, 03 Jul 2020 05:10:41 +0000</pubDate>
      <link>https://dev.to/singhanuj620/can-i-use-variables-in-css-yes-let-s-see-how-13b4</link>
      <guid>https://dev.to/singhanuj620/can-i-use-variables-in-css-yes-let-s-see-how-13b4</guid>
      <description>&lt;p&gt;I am into the web development field for a quite long time now, but I am today year old when discovered that we can use variables in our CSS3.&lt;/p&gt;

&lt;p&gt;So let's get started.&lt;/p&gt;

&lt;p&gt;Assume that you are applying font-family property to 4 or 5 elements and that's where variable comes into action.&lt;/p&gt;

&lt;p&gt;The variable with its property is defined and declared in &lt;strong&gt;:root&lt;/strong&gt; with &lt;strong&gt;--&lt;/strong&gt; prefixed with the variable name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
    --varfont: 'Roboto', sans-serif;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And use it like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1
{
  font-family: var(--varfont);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope it helped you !!!&lt;/p&gt;

&lt;p&gt;Follow me for more such content :&lt;br&gt;
Instagram : &lt;a href="https://instagram.com/anujcodeop"&gt;https://instagram.com/anujcodeop&lt;/a&gt;&lt;br&gt;
Portfolio : &lt;a href="https://anujportfolio.herokuapp.com"&gt;https://anujportfolio.herokuapp.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Using CSS Module in Latest React 16.12.0</title>
      <dc:creator>Anuj Singh</dc:creator>
      <pubDate>Mon, 10 Feb 2020 13:49:39 +0000</pubDate>
      <link>https://dev.to/singhanuj620/using-css-module-in-latest-react-16-12-0-5e86</link>
      <guid>https://dev.to/singhanuj620/using-css-module-in-latest-react-16-12-0-5e86</guid>
      <description>&lt;p&gt;[It's my &lt;strong&gt;first post&lt;/strong&gt;, so please ignore any grammatical mistake] &lt;/p&gt;

&lt;p&gt;In the newer version of reactJS [as per given date 10-FEB-2020 it's 16.12.0], the older way of using &lt;strong&gt;npm run eject will not work&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, &lt;em&gt;to make it work&lt;/em&gt; what we can do is ---&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt; &lt;em&gt;Making CSS file&lt;/em&gt;&lt;br&gt;
While making a CSS file, name it in following convention.&lt;br&gt;
e.g name i want is "index", so instead of naming it "index.css", name it to "&lt;strong&gt;index.module.css&lt;/strong&gt;"&lt;br&gt;
And write css code as usual you are writing earlier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; &lt;em&gt;Importing CSS file&lt;/em&gt;&lt;br&gt;
While importing the "index.module.css" file in another file, eg in App.js, use following command;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;import style from './index.module.css';&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;style&lt;/em&gt; name is upto you, this is used for refering the classes and id inside of css file&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;for using CSS codes use&lt;/strong&gt; className={style.Col}&lt;br&gt;
&lt;em&gt;Col&lt;/em&gt; is the css code inside &lt;em&gt;index.module.css&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
