<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amit Tyagi on Medium]]></title>
        <description><![CDATA[Stories by Amit Tyagi on Medium]]></description>
        <link>https://medium.com/@amitt6580?source=rss-b6a666c54702------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fkkVFuVQjEKbXPSDmf5kdg.jpeg</url>
            <title>Stories by Amit Tyagi on Medium</title>
            <link>https://medium.com/@amitt6580?source=rss-b6a666c54702------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:44:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amitt6580/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[पीपल का पेड़ हिंदू धर्म में पवित्र क्यों माना जाता है?]]></title>
            <link>https://amitt6580.medium.com/%E0%A4%AA%E0%A5%80%E0%A4%AA%E0%A4%B2-%E0%A4%95%E0%A4%BE-%E0%A4%AA%E0%A5%87%E0%A4%A1%E0%A4%BC-%E0%A4%B9%E0%A4%BF%E0%A4%82%E0%A4%A6%E0%A5%82-%E0%A4%A7%E0%A4%B0%E0%A5%8D%E0%A4%AE-%E0%A4%AE%E0%A5%87%E0%A4%82-%E0%A4%AA%E0%A4%B5%E0%A4%BF%E0%A4%A4%E0%A5%8D%E0%A4%B0-%E0%A4%95%E0%A5%8D%E0%A4%AF%E0%A5%8B%E0%A4%82-%E0%A4%AE%E0%A4%BE%E0%A4%A8%E0%A4%BE-%E0%A4%9C%E0%A4%BE%E0%A4%A4%E0%A4%BE-%E0%A4%B9%E0%A5%88-6cdcf345e658?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cdcf345e658</guid>
            <category><![CDATA[religion]]></category>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[archaeology]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[history]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Tue, 03 Nov 2026 09:43:33 GMT</pubDate>
            <atom:updated>2026-11-03T09:43:33.784Z</atom:updated>
            <content:encoded><![CDATA[<h3>पीपल का पेड़ हिंदू धर्म में पवित्र क्यों माना जाता है? जानिए इसके पीछे का विज्ञान, इतिहास और पुरातत्व</h3><p><em>क्या हजारों साल पहले हमारे पूर्वजों ने पीपल के पेड़ को केवल धार्मिक आस्था के कारण पवित्र माना था, या इसके पीछे प्रकृति, पर्यावरण और मानव जीवन से जुड़ा कोई गहरा वैज्ञानिक कारण भी था?</em></p><p>भारत में शायद ही कोई ऐसा व्यक्ति होगा जिसने पीपल का पेड़ न देखा हो।</p><p>गाँवों में पुराने मंदिरों के पास, शहरों के चौराहों पर और प्राचीन धार्मिक स्थलों में पीपल का विशाल वृक्ष अक्सर दिखाई देता है।</p><p>कई लोग सुबह इसके नीचे दीपक जलाते हैं, जल अर्पित करते हैं और इसकी परिक्रमा करते हैं। हिंदू परंपरा में इसे अत्यंत पवित्र माना जाता है।</p><p>लेकिन एक सवाल बहुत दिलचस्प है।</p><p><strong>आखिर हजारों साल पहले हमारे पूर्वजों ने पीपल के पेड़ को ही इतना विशेष स्थान क्यों दिया?</strong></p><p>क्या यह केवल धार्मिक विश्वास था? क्या प्राचीन भारतीय ऋषियों को इस पेड़ के पर्यावरणीय महत्व की जानकारी थी? क्या पुरातत्व में ऐसे प्रमाण मिलते हैं जो बताते हैं कि पीपल का महत्व हमारी सभ्यता में बहुत पुराना है?</p><p>इस सवाल का जवाब खोजने के लिए हमें धर्मग्रंथों, प्राचीन सभ्यताओं, वनस्पति विज्ञान और आधुनिक वैज्ञानिक शोध को एक साथ समझना होगा।</p><h3>1. पीपल का पेड़ वास्तव में क्या है?</h3><p>सबसे पहले इसके वैज्ञानिक परिचय को समझते हैं।</p><p>पीपल का वैज्ञानिक नाम <em>Ficus religiosa</em> है। यह Moraceae यानी अंजीर परिवार का सदस्य है।</p><p>इसे अंग्रेजी में Sacred Fig या Sacred Bo Tree भी कहा जाता है।</p><p>इस पेड़ की कुछ विशेष पहचान हैं:</p><ul><li>इसके पत्ते हृदय के आकार के होते हैं।</li><li>पत्तों का ऊपरी सिरा लंबा और नुकीला होता है।</li><li>यह बहुत बड़ा और विस्तृत छायादार वृक्ष बन सकता है।</li><li>इसके छोटे फल पकने पर बैंगनी रंग के हो सकते हैं।</li><li>यह कई दशकों से लेकर बहुत लंबी अवधि तक जीवित रह सकता है।</li></ul><p>पीपल भारत, नेपाल, श्रीलंका और दक्षिण एशिया के कई अन्य क्षेत्रों में पाया जाता है।</p><p>भारत सरकार के CSIR-NEERI के जैव विविधता पोर्टल पर भी पीपल की प्रजाति और उसकी विशेषताओं का विवरण उपलब्ध है।</p><p>स्रोत: CSIR-NEERI Biodiversity Portal<br><a href="https://neeriathome.neeri.res.in/biodiversity/Peepal.php">https://neeriathome.neeri.res.in/biodiversity/Peepal.php</a></p><h3>2. क्या सिंधु घाटी सभ्यता में भी पीपल का महत्व था?</h3><p>यह इस विषय का सबसे दिलचस्प ऐतिहासिक पहलू है।</p><p>सिंधु घाटी सभ्यता लगभग 2600–1900 ईसा पूर्व के दौरान अपने विकसित शहरी चरण में थी।</p><p>इस सभ्यता से प्राप्त कई पुरातात्विक वस्तुओं पर पेड़ों, पशुओं और प्रकृति से जुड़े चित्र दिखाई देते हैं।</p><p>दिलचस्प बात यह है कि अमेरिका के लॉस एंजिल्स काउंटी म्यूजियम ऑफ आर्ट (LACMA) में संरक्षित एक प्राचीन पात्र पर पीपल के पेड़ की आकृति का उल्लेख मिलता है।</p><p><strong>संग्रहालय का आधिकारिक रिकॉर्ड:</strong></p><ul><li>वस्तु: Ceremonial Vessel</li><li>काल: लगभग 2600–2450 ईसा पूर्व</li><li>संग्रहालय: Los Angeles County Museum of Art (LACMA)</li><li>विशेषता: पात्र के ऊपरी हिस्से में पीपल के वृक्ष और अन्य वनस्पति आकृतियाँ बनी हैं।</li></ul><p>आधिकारिक संग्रहालय रिकॉर्ड:</p><p><a href="https://collections.lacma.org/object/64836">https://collections.lacma.org/object/64836</a></p><p>यह प्रमाण महत्वपूर्ण है क्योंकि इससे पता चलता है कि सिंधु सभ्यता की कलात्मक परंपरा में पीपल के वृक्ष का चित्रण मौजूद था।</p><p>हालाँकि, किसी पात्र पर पेड़ की आकृति होने से यह अपने आप सिद्ध नहीं होता कि उस समय लोग उसकी पूजा भी करते थे।</p><p>लेकिन यह हमें एक महत्वपूर्ण सवाल जरूर देता है:</p><p>क्या पीपल का सांस्कृतिक महत्व भारतीय धार्मिक परंपराओं से भी पहले शुरू हो चुका था?</p><p>इसका निश्चित उत्तर देने के लिए और पुरातात्विक शोध की आवश्यकता है।</p><h3>3. हिंदू धर्म में पीपल को देवताओं का निवास क्यों माना गया?</h3><p>हिंदू धार्मिक परंपरा में पीपल को अश्वत्थ कहा जाता है। इसका उल्लेख प्राचीन भारतीय साहित्य में मिलता है।</p><p>भगवद्गीता के दसवें अध्याय में भगवान श्रीकृष्ण कहते हैं:</p><p><strong>“अश्वत्थः सर्ववृक्षाणाम्”</strong></p><p>अर्थात वृक्षों में मैं अश्वत्थ हूँ।</p><p>यह भगवद्गीता के अध्याय 10, श्लोक 26 में मिलता है।</p><p>यहाँ भगवान कृष्ण अश्वत्थ वृक्ष को अपनी विभूति के रूप में प्रस्तुत करते हैं।</p><p>भगवद्गीता के अध्याय 15 में भी अश्वत्थ वृक्ष का उल्लेख एक विशेष दार्शनिक प्रतीक के रूप में किया गया है।</p><p>वहाँ संसार की तुलना एक ऐसे वृक्ष से की गई है जिसकी जड़ें ऊपर और शाखाएँ नीचे हैं।</p><p>इसका अर्थ केवल एक पेड़ का वर्णन करना नहीं है, बल्कि संसार, जीवन, कर्म और अस्तित्व की गहरी दार्शनिक व्याख्या करना है।</p><p>इसके अलावा अथर्ववेद और बाद के धार्मिक साहित्य में भी अश्वत्थ का उल्लेख मिलता है।</p><p>एक शोध लेख, जो PubMed पर उपलब्ध है, अश्वत्थ के धार्मिक, सांस्कृतिक और औषधीय महत्व का ऐतिहासिक अध्ययन प्रस्तुत करता है।</p><p>शोध संदर्भ:</p><p>Medico-historical study of Aśvattha (Sacred Fig Tree)</p><p><a href="https://pubmed.ncbi.nlm.nih.gov/18175640/">https://pubmed.ncbi.nlm.nih.gov/18175640/</a></p><p>इससे स्पष्ट होता है कि पीपल का धार्मिक महत्व भारतीय परंपरा में बहुत पुराना है।</p><h3>4. भगवान बुद्ध और पीपल का पेड़: बोधि वृक्ष का रहस्य</h3><p>पीपल के पेड़ का महत्व केवल हिंदू धर्म तक सीमित नहीं है।</p><p>बौद्ध धर्म में भी इसे अत्यंत पवित्र स्थान प्राप्त है।</p><p>बौद्ध परंपरा के अनुसार सिद्धार्थ गौतम ने बिहार के बोधगया में पीपल के वृक्ष के नीचे ध्यान करते हुए ज्ञान प्राप्त किया था।</p><p>ज्ञान प्राप्ति के बाद वे बुद्ध कहलाए और उस वृक्ष को बोधि वृक्ष के नाम से जाना जाने लगा।</p><p>बोधि का अर्थ है ज्ञान या जागृति।</p><p>इस घटना ने पीपल के पेड़ को बौद्ध धर्म में विशेष आध्यात्मिक पहचान दी।</p><p>श्रीलंका में स्थित अनुराधापुर का श्री महा बोधि वृक्ष भी इसी परंपरा से जुड़ा हुआ है।</p><p>परंपरा के अनुसार इसे सम्राट अशोक के समय बोधगया के मूल बोधि वृक्ष की शाखा से लगाया गया था।</p><p>यह वृक्ष बौद्ध इतिहास और धार्मिक परंपरा का एक महत्वपूर्ण जीवित प्रतीक है।</p><p>यहाँ एक विशेष बात समझने योग्य है।</p><p>हिंदू धर्म में पीपल को देवत्व और जीवन के प्रतीक के रूप में देखा जाता है, जबकि बौद्ध धर्म में यह ज्ञान, जागृति और ध्यान का प्रतीक बन गया।</p><p>दोनों परंपराओं में एक ही वृक्ष को इतना महत्वपूर्ण स्थान मिलना भारतीय सांस्कृतिक इतिहास की एक उल्लेखनीय विशेषता है।</p><h3>5. पीपल का पेड़ पर्यावरण के लिए इतना महत्वपूर्ण क्यों है?</h3><p>अब इस विषय को आधुनिक विज्ञान की दृष्टि से समझते हैं।</p><p>पीपल केवल एक धार्मिक वृक्ष नहीं है। यह पारिस्थितिकी तंत्र में भी महत्वपूर्ण भूमिका निभाता है।</p><p>इसका सबसे बड़ा कारण है इसका अंजीर परिवार से संबंध।</p><p>Ficus प्रजातियों के पेड़ अनेक पक्षियों, कीटों और दूसरे जीवों को भोजन प्रदान करते हैं।</p><p>पीपल के छोटे फल कई पक्षियों और फल खाने वाले जीवों के लिए भोजन का स्रोत बनते हैं।</p><p>जब प्राकृतिक जंगलों में दूसरे पेड़ों पर फल उपलब्ध नहीं होते, तब कुछ Ficus प्रजातियाँ जीवों के लिए महत्वपूर्ण खाद्य स्रोत बनी रह सकती हैं।</p><p>इसी कारण कई वैज्ञानिक अध्ययनों में Ficus प्रजातियों को keystone ecological species के रूप में महत्वपूर्ण माना गया है।</p><p>Keystone species का अर्थ ऐसी प्रजाति से है जिसका पारिस्थितिकी तंत्र पर उसके आकार या संख्या की तुलना में बहुत अधिक प्रभाव होता है।</p><p>पीपल के पेड़ के पारिस्थितिक महत्व पर भारतीय विज्ञान अकादमी के शोधकर्ताओं ने भी अध्ययन किया है।</p><p>शोध का नाम:</p><p><strong>Ecology of Ficus religiosa accounts for its association with religion</strong></p><p>लेखक: V. Sitaramam, S. R. Jog और P. Tetali</p><p>प्रकाशन: Current Science, 2009, Volume 97, Pages 637–640.</p><p>शोध लिंक:</p><p><a href="https://repository.ias.ac.in/49836/">https://repository.ias.ac.in/49836/</a></p><p>यह अध्ययन पीपल के पारिस्थितिक और सांस्कृतिक महत्व के बीच संबंध पर चर्चा करता है।</p><p>इससे एक दिलचस्प संभावना सामने आती है।</p><p>प्राचीन समाजों में जिन पेड़ों से पक्षियों, जीवों और मनुष्यों को लाभ मिलता था, उन्हें विशेष सांस्कृतिक महत्व देना प्रकृति संरक्षण का एक प्रभावी तरीका भी हो सकता था।</p><h3>6. पीपल और छोटी ततैया का अनोखा वैज्ञानिक संबंध</h3><p>पीपल के पेड़ की सबसे रोचक वैज्ञानिक विशेषताओं में से एक है इसका परागण।</p><p>क्या आप जानते हैं कि पीपल के फल वास्तव में सामान्य अर्थों में साधारण फल नहीं होते?</p><p>वे विशेष प्रकार की संरचनाएँ होती हैं जिन्हें वैज्ञानिक भाषा में Syconium कहा जाता है।</p><p>इनके अंदर बहुत छोटे फूल होते हैं।</p><p>इन फूलों के परागण में विशेष प्रकार की छोटी ततैयों की भूमिका होती है।</p><p>यह एक अत्यंत दिलचस्प प्राकृतिक साझेदारी है।</p><p>पीपल और उसकी परागण करने वाली ततैया के बीच एक प्रकार का सहजीवी संबंध (Mutualism) होता है।</p><p>इसमें:</p><ul><li>ततैया पेड़ की विशेष संरचना के अंदर प्रवेश करती है।</li><li>वह परागण की प्रक्रिया में सहायता करती है।</li><li>ततैया को प्रजनन के लिए उपयुक्त वातावरण मिलता है।</li><li>पेड़ को फल और बीज विकसित करने में सहायता मिलती है।</li></ul><p>इस तरह एक बहुत छोटा कीट एक विशाल पेड़ के जीवन चक्र में महत्वपूर्ण भूमिका निभाता है।</p><p>यह प्रकृति में मौजूद जटिल पारस्परिक संबंधों का सुंदर उदाहरण है।</p><p>यह भी एक कारण है कि Ficus प्रजातियों को जैव विविधता के अध्ययन में महत्वपूर्ण माना जाता है।</p><h3>7. क्या पीपल रात में भी ऑक्सीजन देता है? विज्ञान क्या कहता है?</h3><p>पीपल के बारे में इंटरनेट पर एक बहुत लोकप्रिय दावा किया जाता है।</p><p>कहा जाता है कि पीपल का पेड़ रात में भी ऑक्सीजन छोड़ता है।</p><p>लेकिन क्या यह वैज्ञानिक रूप से सही है?</p><p>इसे समझने के लिए हमें प्रकाश संश्लेषण (Photosynthesis) की प्रक्रिया समझनी होगी।</p><p>अधिकांश हरे पौधे सूर्य के प्रकाश की सहायता से कार्बन डाइऑक्साइड और पानी का उपयोग करके भोजन बनाते हैं। इस प्रक्रिया में ऑक्सीजन निकलती है।</p><p>सामान्य प्रकाश संश्लेषण के लिए प्रकाश आवश्यक है।</p><p>कुछ पौधे CAM नामक विशेष प्रकार की कार्बन-स्थिरीकरण प्रक्रिया अपनाते हैं, जिसमें रात में कार्बन डाइऑक्साइड ग्रहण किया जा सकता है।</p><p>लेकिन इसका अर्थ यह नहीं है कि हर ऐसा पौधा रात भर बड़ी मात्रा में ऑक्सीजन छोड़ता है।</p><p>पीपल के बारे में रात में ऑक्सीजन देने का दावा अक्सर बिना पर्याप्त वैज्ञानिक प्रमाण के दोहराया जाता है।</p><p>2023 में प्रकाशित एक शोध में Ficus religiosa के जीनोम और दिन-रात के दौरान उसकी पत्तियों में सक्रिय जैविक प्रक्रियाओं का अध्ययन किया गया।</p><p>शोध का नाम:</p><p><strong>Genomic and transcriptomic analysis of sacred fig (Ficus religiosa)</strong></p><p>यह शोध पीपल के पौधे में कार्बन-स्थिरीकरण से संबंधित जीनों और जैविक प्रक्रियाओं का अध्ययन करता है।</p><p>शोध लिंक:</p><p><a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC10100241/">https://pmc.ncbi.nlm.nih.gov/articles/PMC10100241/</a></p><p>इस शोध को पीपल द्वारा रात में बड़ी मात्रा में ऑक्सीजन छोड़ने का प्रमाण नहीं समझना चाहिए।</p><p>इसलिए अधिक सही वैज्ञानिक निष्कर्ष यही है कि पीपल भी अन्य हरे वृक्षों की तरह प्रकाश संश्लेषण करता है और पर्यावरण के लिए उपयोगी है, लेकिन रात में विशेष मात्रा में ऑक्सीजन देने का लोकप्रिय दावा स्थापित वैज्ञानिक तथ्य नहीं है।</p><h3>8. क्या पीपल का पेड़ प्राचीन भारत में पर्यावरण संरक्षण का तरीका था?</h3><p>यह एक ऐसा सवाल है जिस पर विशेष ध्यान देने की आवश्यकता है।</p><p>आज दुनिया के सामने जलवायु परिवर्तन, वनों की कटाई और जैव विविधता के नुकसान जैसी बड़ी समस्याएँ हैं।</p><p>हम पर्यावरण बचाने के लिए कानून बनाते हैं, जागरूकता अभियान चलाते हैं और नए पेड़ लगाने की बात करते हैं।</p><p>लेकिन प्राचीन भारतीय समाज में पेड़ों को धार्मिक और सांस्कृतिक महत्व देना भी उनके संरक्षण का एक माध्यम हो सकता था।</p><p>जब किसी पेड़ को पवित्र माना जाता है, तो लोग उसे काटने से बचते हैं।</p><p>उसके आसपास धार्मिक गतिविधियाँ होती हैं। लोग उसकी देखभाल करते हैं और उसकी छाया में बैठते हैं।</p><p>David L. Haberman की पुस्तक <em>People Trees: Worship of Trees in Northern India</em> में उत्तर भारत में वृक्ष पूजा की परंपरा का विस्तृत सामाजिक और सांस्कृतिक अध्ययन किया गया है।</p><p>Oxford University Press, 2013.</p><p><a href="https://academic.oup.com/book/3132">https://academic.oup.com/book/3132</a></p><p>इसके अलावा Assam में किए गए एक Ethnobiology अध्ययन में भी पाया गया कि कुछ ग्रामीण समुदायों में Ficus प्रजातियों के पेड़ों को काटने के प्रति धार्मिक निषेध मौजूद हैं।</p><p>शोध:</p><p><a href="https://www.ojs.ethnobiology.org/index.php/ebl/article/view/269">https://www.ojs.ethnobiology.org/index.php/ebl/article/view/269</a></p><p>इससे पता चलता है कि धार्मिक मान्यताएँ कई बार प्राकृतिक संसाधनों के संरक्षण में योगदान दे सकती हैं।</p><p>हालाँकि यह कहना सही नहीं होगा कि प्राचीन ऋषियों ने आधुनिक पर्यावरण विज्ञान के सभी सिद्धांतों को पहले से जान लिया था।</p><p>लेकिन इतना अवश्य कहा जा सकता है कि प्रकृति को सम्मान देने की परंपरा पर्यावरण संरक्षण के लिए उपयोगी साबित हो सकती है।</p><h3>9. क्या पीपल का पेड़ औषधीय गुण भी रखता है?</h3><p>आयुर्वेद और पारंपरिक भारतीय चिकित्सा में पीपल के पत्तों, छाल और अन्य भागों का उल्लेख मिलता है।</p><p>आधुनिक शोध में भी Ficus religiosa के विभिन्न हिस्सों में कई प्रकार के जैव सक्रिय रासायनिक यौगिकों का अध्ययन किया गया है।</p><p>इनमें कुछ ऐसे यौगिक शामिल हैं जिनकी एंटीऑक्सिडेंट और अन्य जैविक गतिविधियों पर प्रयोगशाला स्तर पर शोध हुआ है।</p><p>लेकिन यहाँ एक जरूरी अंतर समझना चाहिए।</p><p>किसी पौधे में औषधीय गुणों वाले रासायनिक पदार्थ मिलना और उस पौधे से किसी बीमारी का प्रभावी इलाज सिद्ध होना दो अलग-अलग बातें हैं।</p><p>हर पारंपरिक उपचार के लिए पर्याप्त मानव-आधारित चिकित्सकीय प्रमाण उपलब्ध नहीं हैं।</p><p>इसलिए पीपल को औषधीय महत्व वाला पौधा कहना उचित है, लेकिन इसे किसी बीमारी का प्रमाणित इलाज बताना उचित नहीं होगा।</p><h3>10. आखिर पीपल को इतना पवित्र क्यों माना गया?</h3><p>अब तक हमने इसके धार्मिक, ऐतिहासिक और वैज्ञानिक पहलुओं को समझा।</p><p>इन सभी को एक साथ रखने पर कुछ महत्वपूर्ण बातें सामने आती हैं:</p><ol><li>प्राचीन भारतीय साहित्य में अश्वत्थ का उल्लेख मिलता है।</li><li>भगवद्गीता में इसे भगवान कृष्ण की विभूतियों में शामिल किया गया है।</li><li>सिंधु सभ्यता के एक प्राचीन पात्र पर पीपल की आकृति का संग्रहालय रिकॉर्ड उपलब्ध है।</li><li>बौद्ध धर्म में यही वृक्ष ज्ञान और जागृति का प्रतीक है।</li><li>जीव विज्ञान के अनुसार Ficus religiosa एक महत्वपूर्ण पारिस्थितिक प्रजाति है।</li><li>इसके फल और परागण की प्रक्रिया कई जीवों के बीच प्राकृतिक संबंधों को दर्शाती है।</li><li>वृक्ष पूजा की परंपरा कई समुदायों में पेड़ों के संरक्षण को बढ़ावा दे सकती है।</li></ol><p>इन तथ्यों से यह समझने में मदद मिलती है कि पीपल का महत्व केवल धार्मिक विश्वास तक सीमित नहीं है।</p><p>इसके साथ मानव सभ्यता, प्रकृति, पर्यावरण और दर्शन का भी गहरा संबंध है।</p><h3>निष्कर्ष: पीपल केवल एक पेड़ नहीं, प्रकृति और मानव सभ्यता के संबंध का प्रतीक है</h3><p>जब हम किसी पुराने पीपल के पेड़ के नीचे खड़े होते हैं, तो शायद हमें केवल उसकी विशाल शाखाएँ और हरे पत्ते दिखाई देते हैं।</p><p>लेकिन उसके पीछे हजारों साल पुरानी सांस्कृतिक परंपराएँ, धार्मिक मान्यताएँ और प्राकृतिक संबंधों की एक लंबी कहानी छिपी है।</p><p>हिंदू धर्म में यह देवत्व का प्रतीक है।</p><p>बौद्ध धर्म में यह ज्ञान और जागृति का प्रतीक है।</p><p>इतिहास में इसकी आकृतियाँ प्राचीन भारतीय कला से जुड़ी हैं।</p><p>विज्ञान में यह जैव विविधता और पारिस्थितिकी के लिए महत्वपूर्ण वृक्ष है।</p><p>शायद हमारे पूर्वजों ने प्रकृति को सम्मान देने के लिए उसे अपने जीवन और धार्मिक परंपराओं का हिस्सा बनाया था।</p><p>और आज आधुनिक विज्ञान हमें यह समझने में मदद करता है कि पेड़ों का संरक्षण केवल धार्मिक कर्तव्य नहीं, बल्कि पृथ्वी पर जीवन को बनाए रखने की आवश्यकता भी है।</p><p><strong>हो सकता है कि पीपल की सबसे बड़ी विशेषता यह न हो कि वह कितना पवित्र है, बल्कि यह हो कि उसके संरक्षण से कितने दूसरे जीवों का जीवन जुड़ा हुआ है।</strong></p><p>अगली बार जब आप किसी पीपल के पेड़ के नीचे खड़े हों, तो उसे केवल एक धार्मिक प्रतीक के रूप में नहीं, बल्कि एक जीवंत पारिस्थितिकी तंत्र के रूप में भी देखने की कोशिश कीजिए।</p><p>क्योंकि प्रकृति की रक्षा करना भी एक प्रकार की पूजा है।</p><h3>संदर्भ और शोध स्रोत (References)</h3><p><strong>प्राचीन इतिहास और पुरातत्व</strong></p><ol><li>Los Angeles County Museum of Art (LACMA), Ceremonial Vessel, circa 2600–2450 BCE.<br><a href="https://collections.lacma.org/object/64836">https://collections.lacma.org/object/64836</a></li></ol><p><strong>धार्मिक और सांस्कृतिक इतिहास</strong></p><ol><li>Medico-historical study of Aśvattha (Sacred Fig Tree). PubMed.<br><a href="https://pubmed.ncbi.nlm.nih.gov/18175640/">https://pubmed.ncbi.nlm.nih.gov/18175640/</a></li><li>David L. Haberman, <em>People Trees: Worship of Trees in Northern India</em>, Oxford University Press, 2013.<br>https://academic.oup.com/book/3132</li><li>Bhagavad Gita, Chapter 10, Verse 26 and Chapter 15, Verses 1–3.</li></ol><p><strong>वनस्पति विज्ञान और पारिस्थितिकी</strong></p><ol><li>CSIR-NEERI Biodiversity Portal — Peepal, Ficus religiosa.<br><a href="https://neeriathome.neeri.res.in/biodiversity/Peepal.php">https://neeriathome.neeri.res.in/biodiversity/Peepal.php</a></li><li>Ecology of Ficus religiosa accounts for its association with religion. Current Science, 2009.<br><a href="https://repository.ias.ac.in/49836/">https://repository.ias.ac.in/49836/</a></li><li>Genomic and transcriptomic analysis of sacred fig (Ficus religiosa). BMC Genomics, 2023.<br><a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC10100241/">https://pmc.ncbi.nlm.nih.gov/articles/PMC10100241/</a></li><li>Felling Ficus: The Cultural Status of Fig Trees in a Rural Assamese Community, India. Ethnobiology Letters.<br><a href="https://www.ojs.ethnobiology.org/index.php/ebl/article/view/269">https://www.ojs.ethnobiology.org/index.php/ebl/article/view/269</a></li></ol><p><em>लेखक की टिप्पणी: इस लेख में धार्मिक मान्यताओं, ऐतिहासिक साक्ष्यों और वैज्ञानिक शोध को अलग-अलग रखा गया है। जहाँ किसी ऐतिहासिक पहचान या वैज्ञानिक दावे पर मतभेद हैं, वहाँ उन्हें स्थापित तथ्य के रूप में प्रस्तुत नहीं किया गया है।</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cdcf345e658" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js 20 Is End-of-Life: Why You Should Migrate to Node.js 24]]></title>
            <link>https://amitt6580.medium.com/node-js-20-is-end-of-life-why-you-should-migrate-to-node-js-24-e66122187f9a?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/e66122187f9a</guid>
            <category><![CDATA[full-stack-developer]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[nodejs-update]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[node-red]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Mon, 02 Nov 2026 15:51:01 GMT</pubDate>
            <atom:updated>2026-11-02T15:51:01.959Z</atom:updated>
            <content:encoded><![CDATA[<h3>Node.js 20 to Node.js 24: A Deep Dive into Runtime Migration, Breaking Changes, and Production Challenges</h3><p><strong>A practical guide for backend developers migrating production applications to a newer Node.js runtime.</strong></p><h3>Introduction</h3><p>Recently, many engineering teams have started receiving requests to migrate their existing Node.js applications from Node.js 20 to Node.js 24.</p><p>At first glance, this might look like a straightforward runtime upgrade:</p><pre>nvm install 24<br>nvm use 24</pre><p>But upgrading a production application is rarely that simple.</p><p>A Node.js major-version upgrade can affect the JavaScript engine, cryptographic libraries, HTTP behavior, native modules, package compatibility, and even existing authentication integrations.</p><p>So, what exactly changed? Why is Node.js 20 no longer recommended? And what should developers validate before moving production workloads to Node.js 24?</p><p>Let’s explore this from an engineering perspective.</p><h3>1. Understanding the Node.js Release Lifecycle</h3><p>Node.js follows a release lifecycle designed to provide predictable maintenance and security updates.</p><p>The major stages include:</p><ul><li>Current: New features and improvements are introduced.</li><li>Active LTS: Recommended for production applications, with active maintenance and security updates.</li><li>Maintenance LTS: Primarily receives critical bug fixes and security updates.</li><li>End-of-Life: Official maintenance and security updates stop.</li></ul><h3>Node.js release timeline</h3><p>VersionStatus (November 2026)EOLNode.js 20End-of-LifeApril 30, 2026Node.js 22Maintenance LTSApril 30, 2027Node.js 24Maintenance LTSApril 30, 2028Node.js 26Active LTSApril 30, 2029</p><p>Why does this matter?</p><p>Once a Node.js version reaches EOL, it stops receiving official security fixes. Even if the application continues working, the runtime becomes an increasing security and maintenance risk.</p><p><strong>Engineering takeaway:</strong> Runtime upgrades should be part of regular infrastructure maintenance, not something teams postpone until a production incident occurs.</p><p>Official reference: <a href="https://nodejs.org/en/about/eol">https://nodejs.org/en/about/eol</a></p><h3>2. What’s Different Internally Between Node.js 20 and 24?</h3><p>A Node.js upgrade is more than a JavaScript version update.</p><p>Several important runtime components have changed.</p><h3>2.1 V8 JavaScript Engine</h3><p>Node.js uses Google’s V8 engine to execute JavaScript.</p><p>Node.js 20 uses V8 11.3, whereas Node.js 24 uses V8 13.6.</p><p>The newer engine brings JavaScript language improvements, engine optimizations, and updated runtime behavior.</p><p>For developers, this means:</p><ul><li>Updated JavaScript language support.</li><li>Engine-level performance improvements.</li><li>Changes to runtime behavior.</li><li>Potential differences in edge cases.</li></ul><p>However, a newer V8 engine does not automatically mean every application will become faster. Actual performance depends on application workloads and should be measured through benchmarks.</p><h3>2.2 OpenSSL 3.5</h3><p>One of the most important changes for backend applications is the OpenSSL upgrade.</p><p>Node.js 24 uses OpenSSL 3.5.</p><p>This matters particularly for applications involving:</p><ul><li>HTTPS and TLS communication.</li><li>SSO authentication.</li><li>Certificate validation.</li><li>RSA and ECC keys.</li><li>Digital signatures.</li><li>Secure API integrations.</li></ul><p>OpenSSL 3.5 uses a default security level of 2 in standard Node.js 24 builds.</p><p>This prohibits certain weak cryptographic configurations, including RSA keys shorter than 2048 bits and RC4 cipher suites.</p><p>Consider an enterprise application communicating with an older identity provider.</p><p>If that provider still relies on weak certificates or outdated cipher suites, authentication or TLS connections may fail after upgrading.</p><p><strong>What should you validate?</strong></p><p>Check certificates, key sizes, TLS configurations, and external identity-provider compatibility before deploying.</p><h3>2.3 Native Modules and C/C++ Addons</h3><p>Applications using native Node.js modules may require additional attention.<br>Packages that depend on V8 internals can be sensitive to major-version changes.</p><p>For example:</p><ul><li>bcrypt</li><li>sharp</li><li>Database drivers with native bindings</li><li>Custom C/C++ addons</li></ul><p>Rebuild and test native dependencies against Node.js 24.</p><p>Where possible, prefer Node-API (N-API), which provides a more stable ABI across Node.js versions.</p><h3>3. Breaking Changes Developers Should Know About</h3><p>The most important part of migration is understanding what could break.</p><p>Node.js 24 introduces several behavior and validation changes.</p><p>Some areas worth reviewing include:</p><p>Area What to validateOpenSSLWeak keys and cipher compatibilityFetch APIStricter standards complianceAbortSignalArgument validationStreamsPipe and error handlingBufferChanged behavior and validationHTTP/2Removed priority signaling featuresNative addonsV8 API compatibility</p><h3>Example: HTTP/2 priority signaling</h3><p>Older applications may contain code such as:</p><pre>const session = http2.connect(&#39;https://example.com&#39;);</pre><pre>const stream = session.request({<br>  &#39;:path&#39;: &#39;/&#39;,<br>  &#39;:method&#39;: &#39;GET&#39;<br>});</pre><pre>stream.priority({<br>  weight: 32<br>});</pre><p>The old HTTP/2 priority signaling APIs have been removed.</p><p>If your application depends on these APIs, review the Node.js migration guide and update the implementation.</p><h3>Example: RSA-PSS crypto options</h3><p>Older code may use:</p><pre>const crypto = require(&#39;node:crypto&#39;);</pre><pre>crypto.generateKeyPair(<br>  &#39;rsa-pss&#39;,<br>  {<br>    modulusLength: 2048,<br>    hash: &#39;sha256&#39;,<br>    mgf1Hash: &#39;sha1&#39;<br>  },<br>  callback<br>);</pre><p>The RSA-PSS options hash and mgf1Hash have been deprecated in favor of hashAlgorithm and mgf1HashAlgorithm.</p><p>Updated implementation:</p><pre>const crypto = require(&#39;node:crypto&#39;);</pre><pre>crypto.generateKeyPair(<br>  &#39;rsa-pss&#39;,<br>  {<br>    modulusLength: 2048,<br>    hashAlgorithm: &#39;sha256&#39;,<br>    mgf1HashAlgorithm: &#39;sha1&#39;<br>  },<br>  callback<br>);</pre><p>Always review the official migration guide for the exact changes relevant to your application.</p><h3>4. Dependency Compatibility: The Hidden Migration Challenge</h3><p>In an existing production application, the Node.js runtime is only one part of the dependency chain.</p><p>Consider an application with the following architecture:</p><pre>Client Request<br>                      |<br>                      v<br>                Express Server<br>                      |<br>          +-----------+-----------+<br>          |           |           |<br>          v           v           v<br>       Passport     SSO        OAuth<br>          |           |           |<br>          +-----------+-----------+<br>                      |<br>                      v<br>                 Application<br>                   Logic<br>                      |<br>          +-----------+-----------+<br>          |           |           |<br>          v           v           v<br>        MySQL        AWS        Redis</pre><p>Changing the runtime can expose problems in dependencies that were previously working.</p><p>For example, older versions of middleware packages may not correctly handle edge cases in newer runtime environments.</p><p>Start with:</p><pre>npm outdated<br>npm ls<br>npm audit</pre><p>Don’t blindly upgrade every dependency.</p><p>Instead:</p><ol><li>Identify deprecated packages.</li><li>Check peer dependency requirements.</li><li>Review package changelogs.</li><li>Upgrade incompatible dependencies individually.</li><li>Run regression tests after each meaningful change.</li></ol><p>Keep your existing lockfile and use npm ci for reproducible installations.</p><h3>5. A Real-World Migration Troubleshooting Example</h3><p>One interesting type of issue that developers can encounter during a Node.js migration involves HTTP middleware.</p><p>Consider this error:</p><pre>    at fresh (node_modules/fresh/index.js:29:25)<br>    at SendStream.isFresh (node_modules/send/index.js:352:10)<br>    at SendStream.send (node_modules/send/index.js:508:13)</pre><p>This error can be confusing because the application may have worked perfectly on the previous Node.js version.</p><h3>What does it indicate?</h3><p>The stack trace points to the fresh package, which is involved in HTTP conditional request handling and cache validation.</p><p>The error indicates that the middleware is trying to access a last-modified property on an undefined object.</p><p>However, this does not automatically prove that Node.js 24 introduced a bug.</p><p>Potential investigation areas include:</p><ul><li>Installed versions of fresh and send.</li><li>Express and middleware compatibility.</li><li>Unexpected or missing response-header objects.</li><li>Custom response-handling code.</li><li>Dependency changes between installations.</li></ul><h3>How would I investigate?</h3><p>First, inspect the dependency tree:</p><pre>npm ls fresh send express</pre><p>Then inspect the relevant middleware source:</p><pre>node -p &quot;require.resolve(&#39;fresh&#39;)&quot;<br>node -p &quot;require.resolve(&#39;send&#39;)&quot;</pre><p>Compare the dependency versions between the old and new environments.</p><p>Next, reproduce the request with the same headers and response conditions.</p><p>Pay particular attention to:</p><pre>If-Modified-Since<br>If-None-Match<br>Last-Modified<br>ETag</pre><p>Finally, test the fix against both normal requests and conditional GET requests.</p><p><strong>Important:</strong> Avoid modifying node_modules directly. Identify the responsible dependency or application code and apply a maintainable fix.</p><p>This is why regression testing is essential during runtime migrations.</p><h3>6. Step-by-Step Node.js 24 Migration</h3><p>Let’s look at a practical migration workflow.</p><h3>Step 1: Check the existing environment</h3><pre>node -v<br>npm -v</pre><p>Record the existing versions before making changes.</p><h3>Step 2: Install Node.js 24</h3><p>Using NVM:</p><pre>nvm install 24<br>nvm use 24</pre><pre>node -v<br>npm -v</pre><h3>Step 3: Update package.json</h3><p>Specify the supported runtime:</p><pre>{<br>  &quot;engines&quot;: {<br>    &quot;node&quot;: &quot;&gt;=24 &lt;25&quot;<br>  }<br>}</pre><p>This communicates the intended runtime compatibility to developers and tooling.</p><h3><strong>Step 4: Reinstall dependencies</strong></h3><pre>rm -rf node_modules<br>npm ci</pre><p>Use the existing lockfile rather than generating a completely new dependency tree unnecessarily.</p><h3>Step 5: Review dependency compatibility</h3><pre>npm ls<br>npm audit<br>npm outdated</pre><p>Resolve incompatible or unsupported packages.</p><h3>Step 6: Run application tests</h3><pre>npm test</pre><p>If your project uses Node’s built-in test runner:</p><pre>node --test</pre><h3>Step 7: Validate critical application flows</h3><p>For an enterprise backend, test:</p><ul><li>Authentication and authorization.</li><li>OAuth callbacks.</li><li>Database connections.</li><li>API error handling.</li></ul><h3>Step 8: Deploy to staging</h3><p>Don’t directly replace the production runtime.</p><p>Deploy to staging first, monitor application behavior, and compare results with the previous environment.</p><h3>7. Don’t Forget Docker and CI/CD</h3><p>Updating the local Node.js installation is not sufficient.</p><p>Your deployment pipeline must use the same runtime.</p><p>For example, update your Dockerfile:</p><pre>FROM node:24-bookworm-slim</pre><pre>WORKDIR /app</pre><pre>COPY package*.json ./</pre><pre>RUN npm ci</pre><pre>COPY . .</pre><pre>EXPOSE 3000</pre><pre>CMD [&quot;node&quot;, &quot;server.js&quot;]</pre><p>Also review:</p><ul><li>GitHub Actions or Jenkins configuration.</li><li>AWS deployment environments.</li><li>Kubernetes container images.</li><li>PM2 runtime configuration.</li><li>Environment variables.</li><li>Build and deployment scripts.</li></ul><p>The goal is to maintain runtime consistency across development, testing, staging, and production.</p><h3>8. Production Migration Checklist</h3><p>Before releasing the upgraded application, verify the following:</p><p><strong>Runtime</strong></p><ul><li>Node.js version verified.</li><li>npm version verified.</li><li>Docker image updated.</li><li>CI/CD runtime updated.</li></ul><p><strong>Dependencies</strong></p><ul><li>Deprecated packages reviewed.</li><li>Native modules rebuilt.</li><li>Dependency tree validated.</li><li>Security audit reviewed.</li></ul><p><strong>Application</strong></p><ul><li>API regression tests passed.</li><li>Authentication tested.</li><li>Database connectivity verified.</li><li>HTTP middleware validated.</li><li>Error handling tested.</li></ul><p><strong>Production</strong></p><ul><li>Staging deployment successful.</li><li>CPU and memory monitored.</li><li>Application logs reviewed.</li><li>Rollback plan prepared.</li></ul><h3>9. Should You Choose Node.js 24 or Node.js 26?</h3><p>This is an interesting question in November 2026.</p><p>Node.js 24 is now in Maintenance LTS, whereas Node.js 26 has entered Active LTS.</p><p>ConsiderationNode.js 24Node.js 26 Support phase Maintenance LTS Active LTSEOL April 2028April 2029 Stability Mature LTS Newer LTS Ecosystem compatibility More established Requires additional validation</p><p>If your client explicitly requires Node.js 24, follow that requirement.</p><p>However, if you’re planning a new migration strategy without a fixed runtime requirement, evaluate Node.js 26 as well.</p><p>The decision should consider dependency compatibility, production stability, vendor support, and organizational policies.</p><h3>Conclusion</h3><p>Migrating from Node.js 20 to Node.js 24 is not simply about changing a version number.</p><p>It involves understanding runtime internals, reviewing cryptographic compatibility, validating dependencies, testing application behavior, and ensuring production infrastructure is ready.</p><p>The biggest lesson is that <strong>a successful runtime migration is measured by application stability, not just by whether the server starts successfully.</strong></p><p>As backend developers, we should treat runtime upgrades as engineering projects rather than routine configuration changes.</p><p>If you’re planning your own Node.js migration, start with dependency analysis, test critical application flows, and always validate the upgraded runtime in staging before production.</p><p>Happy coding!</p><h3>References</h3><ol><li><a href="https://github.com/nodejs/Release">Node.js Release Schedule</a></li><li><a href="https://nodejs.org/en/about/eol">Node.js End-of-Life Policy</a></li><li><a href="https://nodejs.org/en/blog/migrations/v22-to-v24">Official Node.js 22 to 24 Migration Guide</a></li><li><a href="https://nodejs.org/en/about/previous-releases">Node.js Releases</a></li><li><a href="https://nodejs.org/docs/latest/api/">Node.js Documentation</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e66122187f9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[In A Knockout Game, You Can’t…”: Sunil Gavaskar On Rohit Sharma’s Off-Form In T20 World Cup]]></title>
            <link>https://amitt6580.medium.com/in-a-knockout-game-you-cant-sunil-gavaskar-on-rohit-sharma-s-off-form-in-t20-world-cup-db9b0fa4920e?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/db9b0fa4920e</guid>
            <category><![CDATA[bcci]]></category>
            <category><![CDATA[indian-cricket-team]]></category>
            <category><![CDATA[icc-t20-world-cup-2022]]></category>
            <category><![CDATA[sunil-gavaskar]]></category>
            <category><![CDATA[rohit-sharma]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 10:24:44 GMT</pubDate>
            <atom:updated>2022-11-08T10:24:44.528Z</atom:updated>
            <content:encoded><![CDATA[<h3>Going into the knockout stages, Rohit Sharma’s form would be crucial for Team India, according to legendary Sunil Gavaskar</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/0*E8EStRAEel7YPK-5" /></figure><p>Sunil Gavaskar feels Rohit’s style of being ultra-aggressive is not doing him any good.</p><p>After a top-place finish in the Group 2, the Indian cricket team now shifts focus to the semi-final against England in the 2022 T20 World Cup on Thursday. This will be the side’s fourth last four appearance in the T20I showpiece event. India will be boosted by the good form of players like <a href="https://sports.ndtv.com/cricket/players/967-virat-kohli-playerprofile">Virat Kohli</a>, <a href="https://sports.ndtv.com/cricket/players/1492-suryakumar-yadav-playerprofile">Suryakumar Yadav</a>, <a href="https://sports.ndtv.com/cricket/players/1688-lokesh-rahul-playerprofile">KL Rahul</a>, Arshdeep Singh among others. However, one senior player who hasn’t quite come to the party is skipper Rohit Sharma. Barring a half-century against Netherlands, he has failed to strike big against Pakistan (4), South Africa (15), Bangladesh (2) and Zimbabwe (15). His string of low scores have put pressure on other batters and going into the knockout stages, Rohit’s form would be crucial for Team India, according to former India captain <a href="https://sports.ndtv.com/cricket/players/40594-sunil-manohar-gavaskar-playerprofile">Sunil Gavaskar</a>.</p><p>“Well, let’s just hope he is saving the runs for the next two matches. They are going to be the biggest matches. In a group game, you know there’s another game to follow, so you maybe sometimes try a little too much and get out. Now, these are knockout games. In a knockout game, you can’t afford to experiment too much. You need to be at your best. Let’s hope that Rohit comes good,” <a href="https://www.indiatoday.in/sports/t20-world-cup-2022/story/t20-world-cup-rohit-sharma-form-sunil-gavaskar-england-semis-2294171-2022-11-07">Gavaskar told India Today.</a></p><p>Gavaskar added that Rohit’s style of being ultra-aggressive is not doing him any good.</p><p>“What’s been happening is, he himself, as the captain of the team, has set this template in the first 6 overs to go bang, bang, and bang. Suddenly, he can’t be seen looking to work the ball around. He is always a good puller of the ball. But on Australian boundaries, that pull shot has got him into trouble,” Gavaskar said.</p><p>“We saw that two years ago as well, he got out twice by playing the pull shot after having scored 40–50 runs (in Tests). That’s got him into trouble again. In a T20 format with just one fielder in the first 6 overs, he has got to be mindful of the fielder and play the pull shot. It’s a productive shot for him, let’s not forget that.”</p><p>Rohit is the only member of the current Indian team, who featured in the 2007 World T20-winning side. Being the skipper as well as the senior opener, Indian cricket fans would hope Rohit to come good in the knockout stage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db9b0fa4920e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is REDIS and what is the use of REDIS and how to set the value in REDIS.]]></title>
            <link>https://amitt6580.medium.com/what-is-redis-and-what-is-the-use-of-redis-and-how-to-set-the-value-in-redis-ec9308fe4141?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec9308fe4141</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[chetu]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Thu, 15 Sep 2022 15:15:20 GMT</pubDate>
            <atom:updated>2022-09-15T15:15:20.263Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is REDIS and what is the use of REDIS and how to set the value in REDIS</h3><p>Understand the concept of distributed, in-memory key-value database, cache, and message broker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*A7p59CnJpa-dBi3n.jpeg" /></figure><h3>Introduction</h3><p>Modern world web applications require a lot of things up and running on the server to serve the purpose of users. Many developers don’t know about the factors which can ruin a user’s experience. It depends on how well the code is optimized, how the server responds, how well the database is integrated and so. This may depend on the framework or the language developers use. But, Developers can optimize their application which can significantly increase the overall performance. One such thing they can optimize to increase the performance is by using efficient database connection and utilizing it for quick responses. Well, here is where <strong>Redis</strong> comes into play.</p><h3>Overview</h3><p>Let’s take a look at the contents that we will cover in this article.</p><ul><li>What is Redis?</li><li>Where is Redis used?</li><li>Merits of using Redis</li><li>Installing Redis</li><li>Implementation of Redis</li><li>Conclusion</li></ul><h3>What is Redis?</h3><p><em>Redis</em> (or) <em>Remote Dictionary Server</em> is an open-source, in-memory data structure store, used as a distributed, in-memory key-value database, cache, and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*mQR8VIOWbDiJ5CN_.png" /></figure><p>Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster. Redis supports cross platforms which means that you can simply run Redis on Windows, Mac, or any Linux-based systems. Redis recommends using Linux-Based Systems on their Official Documentation <a href="https://redis.io/topics/introduction">page</a>.</p><h3>Where is Redis used?</h3><p>Redis can be used in a lot of applications that we use in our everyday life. Redis helps to store and retrieve data in memory very easily and efficiently. Some of the use cases of Redis are:</p><ul><li>Caching</li><li>Messaging and Queue</li><li>Session Store</li><li>Machine Learning</li><li>Real-Time Analytics</li></ul><p><strong>Caching: </strong>Redis is perfect for implementing a high in-memory cache to decrease data access latency and increase throughput. They can respond in milliseconds which makes it pretty fast and it also enables you to easily scale for higher loads without spending a huge amount of money for just the backend.<strong> </strong>Database query results caching, persistent session caching, web page caching, and caching of frequently used objects such as images, files, and metadata are all popular examples of caching with Redis.</p><p><strong>Messaging and Queue: </strong>Redis also supports Pub/Sub (Publish and Subscribe) with pattern matching and a variety of data structures. This enables Redis to support high-performance messaging, chat rooms, and server intercommunication. We have used a lightweight queue using the Redis List data structure. Lists are ideal for a variety of applications that needs a reliable message broker as it offers atomic operations as well as blocking capabilities.</p><p><strong>Session Store:</strong> For internet-scale applications, Redis is the best choice as it supports in-memory. It provides sub-millisecond latency, scale, and resiliency required to manage session data like session state, credentials, and more.</p><p><strong>Machine Learning: </strong>As we know, Machine Learning models can be a slow and time-consuming process to load some data as inputs and process it to produce outputs. This process can be handled by Redis and the application performance can be increased significantly. With this, many machine learning models can be deployed in production and have a smooth functionality with users.</p><p><strong>Real-Time Analytics:</strong> As Redis handles data with sub-millisecond latency, it is the perfect choice for real-time analytics like social media analytics, ad targeting, personalization, Artificial Intelligence-based applications, Cyber Security, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*4L02zckHR1a3eixV.png" /></figure><h3>Merits of using Redis</h3><p>Redis is great for delivering results faster and managing data that is to store and retrieve it. Some merits of Redis are:</p><ul><li><strong>Faster Database responses</strong>: They store data in RAM, rather than on an HDD (Hard Disk Drive) or SSD (Solid State Drive).</li><li><strong>Has Control over Lifetime of a Data</strong>: Redis supports the Time to Live (TTL) feature where if the keys are set in TTL mode with the duration time to live, data will expire after this time elapses.</li><li><strong>Key-Based Access</strong>: Redis is based on a key-value model. Key-Based access allows for extremely efficient access times. We can access the data using Redis GET and SET semantics. They are very fast though, they can perform around 110, 000 SETs per second and around 81, 000 GETs per second.</li><li><strong>Language Support</strong>: Redis is supported by most of the programming languages like Python, C, C++, Java, JavaScript, and more. You can access the full language support <a href="https://redis.io/clients">here</a>.</li></ul><p>Okay, enough talking though, let’s try some Redis for ourselves, shall we….</p><h3>Installing Redis</h3><p>First of all, open your terminal and start typing the following:</p><p><strong>Note: I am using Ubuntu here for windows or other operating systems you can install it by downloading from the official Redis </strong><a href="http://redis.io/"><strong>website</strong></a><strong>.</strong></p><p><em>Update your Packages</em></p><pre>sudo apt-get update<br>sudo apt-get upgrade</pre><p>Install Redis Server</p><pre>sudo apt-get install redis-server</pre><p>This would have installed Redis on your Ubuntu System. Now follow one more command and you good to go.</p><pre>sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.default</pre><p>That’s it. Redis is perfectly installed and to make sure it works use the following command.</p><pre>redis-cli</pre><p>this should have opened a Command Line Interface with your localhost and port number in it.</p><pre>127.0.0.1:6379&gt;</pre><p>if your output looks something like this then congratulations you have to install Redis on your Ubuntu.</p><h3>Implementation of Redis</h3><p>Let’s get started with a simple implementation of Redis. So, go ahead and start your terminal and start the Redis server using the <strong><em>redis-cli</em></strong> command. Here, we used very simple SET and GET operations but you can definitely explore more such commands from <a href="https://redis.io/commands"><strong><em>here</em></strong></a>.</p><ul><li><strong>SET</strong> in Redis: It sets a value to a key as shown below (used to store data).</li></ul><pre>&gt; SET myKey &quot;1&quot;</pre><ul><li><strong>GET</strong> in Redis: It gets the value using the key as shown below (used to retrieve data).</li></ul><pre>&gt; GET myKey</pre><ul><li><strong>SET</strong> using Key Spaces</li></ul><pre>&gt; SET server:name google<br>&gt; SET server:port 8080</pre><ul><li><strong>GET</strong> using Key Spaces</li></ul><pre>&gt; GET server:name<br>&gt; GET server:port</pre><ul><li>Use <strong>FLUSHALL</strong> to Remove all the data</li></ul><pre>&gt; FLUSHALL</pre><h3>Conclusion</h3><p>In this article, we have seen Redis and its functionalities. We went through the concept of in-memory structure store, message broker, cache, and its effective use in the real-world scenario. We even installed Redis on Ubuntu and learned some Redis commands that help us store and retrieve data efficiently. I hope this article was useful to you all.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec9308fe4141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interfaces in TypeScript: What are they and how do we use them]]></title>
            <link>https://amitt6580.medium.com/interfaces-in-typescript-what-are-they-and-how-do-we-use-them-314eb5659301?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/314eb5659301</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[chetu]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Tue, 26 Oct 2021 06:09:33 GMT</pubDate>
            <atom:updated>2021-10-26T06:09:33.049Z</atom:updated>
            <content:encoded><![CDATA[<p>April 19, 2019 13 min read</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rbpb1cIz5XbwdmoC.png" /></figure><p>JavaScript gives developers a great deal of flexibility. A variable initialized as an integer can be assigned a function literal at run-time. Types of variables are not predictable in JavaScript. As you can see in the example below, a is initialized as an integer and is then assigned a function literal:</p><pre>var a = 2<br>a = function () {<br>  console.log(&quot;I was initialized with a value of an integer, but now I&#39;m a function&quot;)<br>}</pre><p>Let’s consider the implementation plan for building a Tesla Model S car.</p><p>Ten of the Tesla engineers built their prototype model. There were no specifications laid down before implementation, so the engineers all came up with their own set of specifications and implementation model. One of these prototypes had the means to show a user the car charging details while the other one had a tire monitoring system in place.</p><p>If a set of specifications were defined beforehand, it would have been convenient and easy for these engineers to implement prototypes based on the specifications. We deal with the same problem while building complex entities in JavaScript:</p><pre>function buildTeslaModelS (teslaObj) {<br>    // Implementation Details<br>}</pre><pre>buildTeslaModelS({<br>    length: 196,<br>    width: 86,<br>    measureTirePressure: function () {<br>    },<br>    wheelbase: 116<br>})</pre><pre>buildTeslaModelS({<br>    length: &quot;196&quot;,<br>    width: &quot;86&quot;,<br>    wheelbase: &quot;116&quot;,<br>    measureRemCharging: function () {<br>    }<br>})</pre><p>The buildTeslaModelS function returns a Tesla Model S car using the parameters as defined in teslaObj. It makes some assumptions for input parameters and returns a model based on those assumptions. It assumes that the length, width, and wheelbase properties would be integers, and it performs some computations based on this assumption.</p><p>However, as you can see in the second function call to buildTeslaModelS, these values are strings, and so the assumption is no longer valid.</p><p>Also, the buildTeslaModelS function doesn’t know that it would have to deal with the measureRemCharging property, so it completely skips that part. It assumes that measureTirePressure is a mandatory property and that it should be present in all of these models. However, when it doesn’t find this property in the second function call, it throws an error at runtime.</p><p>This is an extremely flexible functionality! There should be a way to tell the buildTeslaModelS function the shape of the input teslaObj parameter. It would have been easier if there was a validation check for checking mandatory properties and their types on teslaObj at compile time.</p><p>Here come TypeScript interfaces to help!</p><p>TypeScript has <a href="https://www.typescriptlang.org/docs/handbook/interfaces.html">built-in support for interfaces</a>. An interface defines the specifications of an entity. It lays out the contract that states <em>what</em> needs to be done but doesn’t specify <em>how</em> it will be done.</p><p>In the above example, we can define an interface for the Tesla Model S, and each of its prototypes would then use this interface to come up with their implementation plan for various functionalities as defined in the interface.</p><p>This is the interface for the Tesla Model S:</p><pre>interface TeslaModelS {<br>    length: number;<br>    width: number;<br>    wheelbase: number;<br>    seatingCapacity: number;<br>    getTyrePressure: () =&gt; number;<br>    getRemCharging: () =&gt; number;<br>}</pre><p>An interface contains the name of all the properties along with their types. It also includes the signature for functions along with the type of arguments and return type. For example, getTyrePressure and getRemCharging functions return the value of type number.</p><h2>How to use an interface</h2><p>A class or function can implement an interface to define the implementation of the properties as defined in that interface.</p><p>Let’s write a function to implement TeslaModelS interface:</p><pre>function buildTeslaModelS (teslaObj: TeslaModelS) {<br>}</pre><pre>buildTeslaModelS({<br>    length: &quot;196&quot;,<br>    width: &quot;86&quot;,<br>    wheelbase: &quot;116&quot;,<br>    measureRemCharging: function () {<br>    }<br>})</pre><p>When you run the code shown above, the TypeScript compiler will give the following error:</p><blockquote>Argument of type { length: string; width: string; wheelbase: string; measureRemCharging: () =&gt; void; } is not assignable to parameter of type TeslaModelS. Object literal may only specify known properties, and measureRemCharging does not exist in type TeslaModelS.</blockquote><p>The compiler complains for two reasons:</p><ol><li>The properties length, width, and wheelbase are defined as type number in the interface, so it expects them to be of type number and not string</li><li>The property measureRemCharging is not defined on the interface. It should be named as getRemCharging and it should return an integer. The implementation of an entity should follow the contract as defined in its interface</li></ol><p>To build a Tesla Model S as defined in the interface, we will have to define the function like this:</p><pre>function buildTeslaModelS (teslaObj: TeslaModelS) {<br>}</pre><pre>buildTeslaModelS({<br>    length: 196,<br>    width: 86,<br>    wheelbase: 116,<br>    seatingCapacity: 4,<br>    getTyrePressure: function () {<br>        let tyrePressure = 20 // Evaluated after doing a few complex computations!<br>        return tyrePressure<br>    },<br>    getRemCharging: function () {<br>        let remCharging = 20 // Evaluated after doing a few complex computations!<br>        return remCharging<br>    }<br>})</pre><p>The above implementation of teslaObj is exactly what the interface expects!</p><h2>How to define optional properties in interfaces</h2><p>Interfaces do a great job in making sure the entities are implemented as expected. However, there would be cases when it is not necessary to have all of the properties as defined in the interface. These are called optional properties and are represented in the interface like this:</p><pre>interface TeslaModelS {<br>    length: number;<br>    width: number;<br>    wheelbase: number;<br>    seatingCapacity: number;<br>    getTyrePressure?: () =&gt; number;<br>    getRemCharging: () =&gt; number;<br>}</pre><p>Please note the ? in the getTyrePressure property. The question mark suggests that the property getTyrePressure is optional and is not mandatory for entities to implement this functionality in all models. The compiler won’t complain even if you don’t specify this property in the teslaObj parameter.</p><p>The compiler also checks for excess properties that are not defined in the interface. Let’s say, the teslaObj contains an excess property turningCircle, which is not specified in the TeslaModelS interface:</p><pre>buildTeslaModelS({<br>    length: 196,<br>    width: 86,<br>    wheelbase: 116,<br>    getTyrePressure: function () {<br>        let tyrePressure = 20 // Evaluated after doing a few complex computations!<br>        return tyrePressure<br>    },<br>    getRemCharging: function () {<br>        let remCharging = 20 // Evaluated after doing a few complex computations!<br>        return remCharging<br>    },<br>    turningCircle: 10<br>})</pre><p>The compiler gives the following error:</p><blockquote>Argument of type { length: number; width: number; wheelbase: number; getTyrePressure: () =&gt; number; getRemCharging: () =&gt; number; turningCircle: number; } is not assignable to parameter of type TeslaModelS. Object literal may only specify known properties, and turningCircle does not exist in type TeslaModelS.</blockquote><h2>Read-only properties in interfaces</h2><p>Read-only properties cannot be changed once they are initialized. For example, the properties length, width, wheelbase, and seatingCapacity should never be modified in any case after they are initialized with some fixed value.</p><p>We will have to modify our interface to reflect this change:</p><pre>interface TeslaModelS {<br>    readonly length: number;<br>    readonly width: number;<br>    readonly wheelbase: number;<br>    readonly seatingCapacity: number;<br>    getTyrePressure?: () =&gt; number;<br>    getRemCharging: () =&gt; number;<br>}</pre><p>Note the use of the readonly keyword with the name of the properties. It suggests that these properties cannot be modified after they are initialized with some value.</p><h2>Indexable properties in interfaces</h2><p>Indexable properties, as the name suggests are used for defining types that are indexed into a unique number or a string. For example, we can define a type CustomArray as:</p><p>interface CustomArray { [index: number]: string} let cars: CustomArray = [‘Hatchback’, ‘Sedan’, ‘Land Rover’, ‘Tesla Model S’]console.log(‘Element at position 1’, cars[1]) // ‘Sedan’</p><p><a href="https://gist.github.com/ankitamasand/0245d775fb202da0ea80900fb4d18cf0/raw/4ee57a1cfc91f0e169c58214becd829dbc51b533/indexable-properties.js">view raw</a><a href="https://gist.github.com/ankitamasand/0245d775fb202da0ea80900fb4d18cf0#file-indexable-properties-js">indexable-properties.js </a>hosted with</p><p>by <a href="https://github.com/">GitHub</a></p><p>Please note the cars variable is not an ordinary array and so you cannot use array built-in functions like push, pop, filter, etc. You might argue that it is better to define ordinary arrays instead of using indexable types. Indexable types are helpful when you have to define custom properties and functions that should operate on a range of values of the same data type.</p><p>Since we have clearly put together the specifications of the Tesla Model S in an interface, it has improved the efficiency of the Tesla engineers, and they are now ready with the first set of 100 cars. It is time for the reviewing committee to go through each of the models and test them for performance and other factors:</p><p>interface TeslaModelSMap { engineer: string, model: TeslaModelS, readonly rating: number}interface TeslaModelSReview { [id: number]: TeslaModelSMap} const TeslaModelSReviewQueue: TeslaModelSReview = [ { engineer: ‘John’, model: modelByJohn1, // modelByJohn1 is of type `TeslaModelS` rating: 2 }, { engineer: ‘Ray’, model: modelByRay1, // modelByRay1 is of type `TeslaModelS` rating: 3 }, { engineer: ‘John’, model: modelByJohn2, // modelByJohn2 is of type `TeslaModelS` rating: 4 }, // … other 97 models]</p><p><a href="https://gist.github.com/ankitamasand/0579e6c612a4444b60baa2db171b5dba/raw/1213a39a7147516ec896a194442de55bfb2d9c19/indexable-properties.js">view raw</a><a href="https://gist.github.com/ankitamasand/0579e6c612a4444b60baa2db171b5dba#file-indexable-properties-js">indexable-properties.js </a>hosted with</p><p>by <a href="https://github.com/">GitHub</a></p><p>The TeslaModelSReview interface indexes the group of properties — engineer, model, and rating associated with a particular model into a unique numeric index. The TeslaModelSReviewQueue is of type TeslaModelSReview. It lists down the Tesla models built by different engineers. From the above code, we can see that John has built two models — modelByJohn1 and modelByJohn2, which are rated as 2 and 4, respectively.</p><p>The type of indexer can either be a string or a number. We can also define other properties in TeslaModelSReview interface but these properties should return a subtype of TeslaModelS type.</p><p>The indices of TeslaModelSReview can be made read-only to prevent modifying its values while it is in the review process. We’ll have to change our TeslaModelSReview interface like this:</p><pre>interface TeslaModelSReview {<br>    readonly [id: number]: TeslaModelS<br>}</pre><h2>How to define function types in interfaces</h2><p>An interface can also be used for defining the structure of a function. As we saw earlier, the functions getTyrePressure and getRemCharging are defined as properties on the TeslaModelS interface. However, we can define an interface for functions like this:</p><pre>interface Order {<br>    (customerId: number, modelId: number): boolean <br>}</pre><pre>let orderFn: Order = function (cId, mId) {<br>    // processing the order<br>    return true // processed successfully!<br>}</pre><p>The orderFn function is to type Order. It takes two parameters of type number and returns a value of type boolean.</p><p>There is no need to define the type of parameters again in the definition of orderFn function as you can see in the code above. The compiler just makes one-to-one mapping of the arguments as defined in the interface with the one defined in the function declaration.</p><p>It infers that cId maps to customerId and its type is number and mId maps to modelId and its type is also number. Even the return type for orderFn function is inferred from its definition in the interface.</p><h2>How to use interfaces with classes</h2><p>So far, we’ve learned how a function implements an interface. Now let’s build a class for the TeslaModelS interface.</p><pre>class TeslaModelSPrototype implements TeslaModelS {<br>    length: number;<br>    width: number;<br>    wheelbase: number;<br>    seatingCapacity: number;<br>    private tempCache: string;</pre><pre>    constructor (l, w, wb, sc) {<br>        this.length = l;<br>        this.width = w;<br>        this.wheelbase = wb;<br>        this.seatingCapacity = sc;<br>    }</pre><pre>    getTyrePressure () {<br>        let tyrePressure = 20 // Evaluated after doing a few complex computations!<br>        return tyrePressure<br>    }</pre><pre>    getRemCharging () {<br>        let remCharging = 20 // Evaluated after doing a few complex computations!<br>        return remCharging<br>    }<br>}</pre><pre>let teslaObj = new TeslaModelSPrototype(196, 86, 116, 4)<br>console.log(&#39;Tyre Pressure&#39;, teslaObj.getTyrePressure())</pre><p>The class TeslaModelSPrototype has defined all the properties of an interface. Please note, the interface defines only the public properties of a class. As can be seen from the above code, the property tempCache has an access modifier private and so it is not defined in the interface TeslaModelS.</p><h2>Different types of variables in a class</h2><p>A class has three different types of variables</p><ol><li><strong>Local variables:</strong> A local variable is defined at the function or block level. It exists only until the function or the block is in execution. Every time a function runs, new copies of the local variables are created in memory</li><li><strong>Instance variables:</strong> Instances variables are members of the class. They are used to store the attributes of class objects. Each of the objects has its own copy of instance variables</li><li><strong>Static variables:</strong> Static variables are also called class variables because they are associated with a class as a whole. All of the objects of a class share the same copy of static variables</li></ol><p>Please note interfaces deal only with the instance part of the class. For example, the constructor function comes under the static part. The interface TeslaModelS does not specify anything related to the constructor or the static part.</p><h2>Extending interfaces</h2><p>An interface can extend any other interface and import its properties. This helps in building small and reusable components. For example, we can create different interfaces to handle the different components of the Tesla Model like this:</p><pre>interface Wheel {<br>    wheelBase: number;<br>    controls: Array&lt;string&gt;,<br>    material: string;<br>}</pre><pre>interface Charger {<br>    adapter: string;<br>    connector: string;<br>    location: string;<br>}</pre><pre>interface TeslaModelS extends Wheel, Charger {<br>    // ... All other properties<br>}</pre><p>The TeslaModelS interface extends the properties of the Wheel and the Charger. Instead of dumping all of the properties in a single interface, it is a good practice to make separate interfaces for handling different components.</p><h2>How are type aliases different from interfaces?</h2><p>Type aliases are used for giving a name to a combination of different types in TypeScript.</p><p>For example, we can create a type that can either be of type string or null:</p><pre>type StringOrNull = string | null;</pre><p>Type aliases and interfaces are often used interchangeably in TypeScript. The shape of the TeslaModelS object can also be defined using type like this:</p><pre>type TeslaModelS {<br>    length: number;<br>    width: number;<br>    wheelbase: number;<br>    seatingCapacity: number;<br>    getTyrePressure: () =&gt; number;<br>    getRemCharging: () =&gt; number;<br>}</pre><p>Similar to how interfaces extend other interfaces and type aliases using the keyword, type aliases can also extend other types and interfaces using the intersection operator. Type aliases can also be implemented by a class.</p><p>Type aliases are generally used in cases where we have to define a merge of different types. For example, consider the function renderObject:</p><pre>function renderObject (objShape: Square | Rectangle | Triangle) {\<br>    // ...<br>}</pre><p>The</p><p>renderObject function takes an input parameter objShape. Square, Rectangle, and Triangle are types, and | is called the union operator. objShape can be of type Square, Rectangle, or Triangle. However, the union of shapes cannot be expressed using an interface.</p><p>Interfaces are used for defining a contract regarding the shape of an object; hence they cannot be used with the union of multiple shapes. Even a class cannot implement a type that describes a union of shapes. This is one of the important functional differences between interfaces and type alias.</p><p>When we define two interfaces with the same name, both of them gets merged into one. The resulting interface will have properties from both the interfaces. However, the compiler will complain if we try to define multiple types with the same name.</p><h2>Hybrid types in interfaces</h2><p>In JavaScript, functions are also considered as objects and so it is valid to add properties even on function literals like this:</p><pre>function manufactureCar (type) {<br>    const model = function getModel (type) {<br>        console.log(&#39;inside getModel function&#39;)<br>        // get the model of type as mentioned in the argument<br>    }<br>    model.getCustomerDetails = function  () {<br>        console.log(&#39;inside customer details function&#39;)<br>        // get the details of customer who has purchased this model<br>    }<br>    model.price = 100000<br>    model.trackDelivery = function () {<br>        console.log(&#39;inside trackDelivery function&#39;)<br>        // track the delivery of the model<br>    }<br>    return model<br>}</pre><pre>let tesla = manufactureCar(&#39;tesla&#39;)<br>tesla() // tesla is a function<br>tesla.getCustomerDetails() // getCustomerDetails is a property defined on function</pre><p>As you can see from the above code, the variable model is assigned a value of function and getCustomerDetails, trackDelivery are attached as properties on the model. This is a common pattern in JavaScript. How do we define this pattern with TypeScript interfaces?</p><pre>interface CarDelivery {<br>    (string): TeslaModelS,<br>    getCustomerDetails (): string,<br>    price: number,<br>    trackDelivery (): string<br>}</pre><pre>function manufactureCar (type: string): CarDelivery {<br>    const model = &lt;CarDelivery&gt; function (type: string) {<br>        // get the model of type as mentioned in the argument<br>    }<br>    model.getCustomerDetails = function () {<br>        // get the details of customer who has purchased this model<br>        return &#39;customer details&#39;<br>    }<br>    model.price = 100000<br>    model.trackDelivery = function () {<br>        // track the delivery of the model<br>        return &#39;tracking address&#39;<br>    }<br>    return model<br>}<br>let tesla = manufactureCar(&#39;tesla&#39;)<br>tesla() // tesla is a function<br>tesla.getCustomerDetails() // getCustomerDetails is a property defined on function</pre><p>The object of type CarDelivery is returned from the manufactureCar function. The interface CarDelivery helps in maintaining the shape of the object returned from the manufactureCar function. It makes sure that all the mandatory properties of the model — getCustomerDetails, price, and trackDelivery — are present in the model.</p><h2>How to use generics in interfaces</h2><p>Generics in TypeScript are used when we have to create generic components that can work on multiple data types. For example, we don’t want to restrict our function to accept only number as the input parameter. It should scale as per the use-case and accept a range of types.</p><p>Let’s write code for implementing a stack that handles generic data types:</p><pre>interface StackSpec&lt;T&gt; {<br>    (elements: Array&lt;T&gt;): void<br>}</pre><pre>function Stack&lt;T&gt; (elements) {<br>    this.elements = elements<br>    this.head = elements.length - 1</pre><pre>    this.push = function (number): void {<br>        this.elements[this.head] = number<br>        this.head++<br>    }</pre><pre>    this.pop = function &lt;T&gt;(): T {<br>        this.elements.splice(-1, 1)<br>        this.head--<br>        return this.elements[this.head]<br>    }</pre><pre>    this.getElements = function (): Array&lt;T&gt; {<br>        return this.elements<br>    }<br>}</pre><pre>let stacksOfStr: StackSpec&lt;string&gt; = Stack<br>let cars = new stacksOfStr([&#39;Hatchback&#39;, &#39;Sedan&#39;, &#39;Land Rover&#39;])<br>cars.push(&#39;Tesla Model S&#39;)</pre><pre>console.log(&#39;Cars&#39;, cars.getElements()) // [&#39;Hatchback&#39;, &#39;Sedan&#39;, &#39;Land Rover&#39;, &#39;Tesla Model S&#39;]</pre><p>The interface StackSpec takes in any data-type and puts it in the definition of the function. T is used for defining type. The function Stack takes an array of elements as the input. The Stack has methods — push for adding a new element of type T in the original elements array, pop is used for removing the top-most element of the elements array and getElements function returns all the elements of type T.</p><p>We’ve created a Stack of strings called stacksOfStr, which takes in string and accordingly replaces T with string. We can reuse this stack implementation for creating stacks of number and other data-types.</p><p>We can also create a stack of Tesla Models. Let’s see how we can do that:</p><pre>let stacksOfTesla: StackSpec&lt;TeslaModelS&gt; = Stack<br>let teslaModels = [<br>    {<br>        engineer: &#39;John&#39;,<br>        modelId: 1,<br>        length: 112,<br>        //...<br>    },<br>    // ...<br>]<br>let teslaStack = new stacksOfTesla(teslaModels)<br>console.log(teslaStack) // prints the value of `teslaModels`</pre><p>Please note that we are using the same stack implementation for an array of type TeslaModelS. Generics coupled with interfaces is a powerful tool in TypeScript.</p><h2>How TypeScript compiles interfaces</h2><p>TypeScript does a great job in handling the weird parts of JavaScript. However, the browser doesn’t understand TypeScript and so it has to be compiled down to JavaScript.</p><p>The TypeScript compiler compiles the above TeslaModelSPrototype class as:</p><pre>var TeslaModelSPrototype = /** @class */ (function () {<br>    function TeslaModelSPrototype(l, w, wb, sc) {<br>        this.length = l;<br>        this.width = w;<br>        this.wheelbase = wb;<br>        this.seatingCapacity = sc;<br>    }<br>    TeslaModelSPrototype.prototype.getTyrePressure = function () {<br>        var tyrePressure = 20; // Evaluated after doing a few complex computations!<br>        return tyrePressure;<br>    };<br>    TeslaModelSPrototype.prototype.getRemCharging = function () {<br>        var remCharging = 20; // Evaluated after doing a few complex computations!<br>        return remCharging;<br>    };<br>    return TeslaModelSPrototype;<br>}());<br>var teslaObj = new TeslaModelSPrototype(196, 86, 116, 4);<br>console.log(&#39;Tyre Pressure&#39;, teslaObj.getTyrePressure());</pre><p>I’m using <a href="https://www.typescriptlang.org/play/index.html">TypeScript Playground</a> to see the compiled code. The instance variables — length, width, wheelBase, and seatingCapacity — are initialized in the function TeslaModelSPrototype. The methods getTyrePressure and getRemCharging are defined on the prototype of the function TeslaModelSPrototype.</p><p>The above code is plain JavaScript, so it can run in the browser.</p><h2>Why use interfaces?</h2><p>As you have already learned that the interfaces help in defining a concrete plan for the implementation of an entity. Apart from that, the interfaces also help in the performance of JavaScript engines. This section assumes that you’ve some understanding of JavaScript engines. In this section, we’ll dig deeper into the working of JavaScript engines and understand how interfaces help with the performance.</p><p>Let’s understand how the Compiler sitting on <a href="https://v8.dev/">V8 (JavaScript engine on Chrome)</a> stores objects.</p><p>The interfaces in TypeScript exist only until compile-time. As you can see in the above code that was generated by the TypeScript compiler, there is no mention of interfaces. The properties of TeslaModelS interface (length, width, wheelBase, and seatingCapacity) are added in the TeslaModelSPrototype constructor while the function types are attached on the prototype of TeslaModelSPrototype function. The JavaScript engines don’t know anything related to interfaces.</p><p>If we instantiate thousands of TeslaModelSPrototype cars, we will have to deal with thousands of objects of type TeslaModelS. Each of these objects will have a structure similar to that of the interface. How does JavaScript engine store these thousands of objects of the same shape? Does it make thousands of copies of these objects? Making thousands of copies of similar shape is definitely a waste of memory. The JavaScript engines make just one shape of type TeslaModelS and each of the objects just stores corresponding values of the properties as defined in TeslaModelS interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/0*JkU1Rz6RwShucBQt.png" /><figcaption>Objects share the same shape.</figcaption></figure><p>This is a great performance benefit on the side of JavaScript engines.</p><p>If the objects have different shapes, the engines will have to create different shapes for these objects and handle them accordingly. Interfaces help in keeping the shapes of similar objects intact.</p><h2>How to use interfaces with React</h2><p>Let’s build a simple use-case of displaying the list of Pokemon using React and TypeScript interfaces.</p><p>Here’s the main App Component that renders the Pokemon list in the div container with id root:</p><pre>import React, { Component, Fragment } from &#39;react&#39;;<br>import { render } from &#39;react-dom&#39;;<br>import PokemonList from &#39;./pokemon-list&#39;;<br>import &#39;./style.css&#39;;</pre><pre>const App = () =&gt; {<br>  return (<br>    &lt;Fragment&gt;<br>        &lt;h2&gt;Pokemon List&lt;/h2&gt;<br>        &lt;PokemonList /&gt;<br>      &lt;/Fragment&gt;<br>  )<br>}</pre><pre>render(&lt;App /&gt;, document.getElementById(&#39;root&#39;));</pre><p>The App component renders PokemonList.</p><p>Let’s check the implementation of PokemonList component:</p><pre>import React, { Component } from &#39;react&#39;;<br>import { PokemonListModel } from &#39;./pokemon-model&#39;;</pre><pre>interface PokemonProps {}<br>interface PokemonState {<br>  pokemonList: PokemonListModel | null;<br>}</pre><pre>class PokemonList extends Component&lt;PokemonProps, PokemonState&gt; {</pre><pre>  constructor (props) {<br>    super(props);<br>    this.state = {<br>      pokemonList: null<br>    }<br>  }</pre><pre>  getPokemonList = () =&gt; {<br>    fetch (&#39;https://pokeapi.co/api/v2/pokemon/?limit=50&#39;)<br>      .then (response =&gt; {<br>        return response.json();<br>      })<br>      .then (response =&gt; {<br>        this.setState({ pokemonList: response });<br>      })<br>  }</pre><pre>  render () {<br>    let { pokemonList } = this.state;<br>    return (<br>      &lt;div className=&#39;pokemon-list&#39;&gt;<br>        {<br>          pokemonList &amp;&amp; pokemonList.results.map (pokemon =&gt; {<br>            return (<br>              &lt;div className=&#39;row&#39; key={pokemon.name}&gt;<br>                &lt;span&gt;{pokemon.name}&lt;/span&gt;<br>              &lt;/div&gt;<br>            )<br>          })<br>        }<br>      &lt;/div&gt;<br>    )<br>  }</pre><pre>  componentDidMount () {<br>    this.getPokemonList()<br>  }<br>}</pre><pre>export default PokemonList</pre><p>The PokemonList component fetches the list of Pokemon using the <a href="https://pokeapi.co/">open-source Poke API project</a>. It stores the results of the Pokemon API in the state of the component. The component uses interfaces PokemonProps and PokemonState for defining its props and state. The interface PokemonListModel defines the structure of an object as returned from the Pokemon API.</p><p>Here’s the PokemonListModel interface:</p><pre>export interface PokemonListModel {<br>  count: number;<br>  next: string | null;<br>  previous: string | null;<br>  results: Array<br>}</pre><pre>interface Pokemon {<br>  name: string;<br>  url: string;<br>}</pre><p>Notice the type of results property. It uses the interface Pokemon to define the structure of results. Here’s the demo of the Pokemon application on Stackblitz.</p><h2>Conclusion</h2><p>Interfaces are a powerful way of defining contracts in TypeScript. Let’s recap all that we have learned in this tutorial:</p><ol><li>Interfaces define the specifications of entities and they can be implemented by functions or classes. We can define optional properties on an interface using ? and read-only properties by using the readonly keyword in the property name</li><li>The TypeScript compiler also checks for excess properties on an object and gives an error if an object contains a property that is defined in the interface</li><li>We also learned how to define Indexable properties using interfaces</li><li>Classes can implement an interface. The interface contains the definition for only the instance variables of a class</li><li>Interfaces can be extended to import properties of other interfaces using the extends keyword</li><li>We can use the power of generics with interfaces and build reusable components</li><li>We also learned how interfaces help with the performance of JavaScript engines</li></ol><h2>Full visibility into production React apps</h2><p>Debugging React applications can be difficult, especially when users experience issues that are hard to reproduce. If you’re interested in monitoring and tracking Redux state, automatically surfacing JavaScript errors, and tracking slow network requests and component load time, <a href="https://www2.logrocket.com/react-performance-monitoring">try LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nmCEFmI9m07_XU1D.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m4j7s7q5rPGc-zP7.png" /></figure><p><a href="https://www2.logrocket.com/react-performance-monitoring">LogRocket</a> is like a DVR for web apps, recording literally everything that happens on your React app. Instead of guessing why problems happen, you can aggregate and report on what state your application was in when an issue occurred. LogRocket also monitors your app’s performance, reporting with metrics like client CPU load, client memory usage, and more.</p><p>The LogRocket Redux middleware package adds an extra layer of visibility into your user sessions. LogRocket logs all actions and state from your Redux stores.</p><p>Modernize how you debug your React apps — <a href="https://www2.logrocket.com/react-performance-monitoring">start monitoring for free</a>.</p><h2>Writing a lot of TypeScript? <a href="https://blog.logrocket.com/typescript-meetup-recap/?utm_source=social&amp;utm_medium=organic&amp;utm_campaign=21Q3_WB_TS-Tech-Meetup0930#utm_source=cro-blog&amp;utm_medium=logrocket&amp;utm_campaign=21Q3_WB_TS-Tech-Meetup0930">Watch the recording</a> of our recent TypeScript meetup to learn about writing more readable code.</h2><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*0AtaQbnnESECLqi7.png" /></figure><p>TypeScript brings type safety to JavaScript. There can be a tension between type safety and readable code. Watch the recording for a deep dive on some new features of TypeScript 4.4.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=314eb5659301" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[These are the basic concepts you should know in React.JS (after you learn the basics)]]></title>
            <link>https://amitt6580.medium.com/these-are-the-basic-concepts-you-should-know-in-react-js-after-you-learn-the-basics-d31156d759c4?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/d31156d759c4</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[chetu]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[begginer]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Mon, 14 Jun 2021 11:20:52 GMT</pubDate>
            <atom:updated>2021-06-14T11:20:52.021Z</atom:updated>
            <content:encoded><![CDATA[<p>You’ve followed your first React.js tutorial and you’re feeling great. Now what? In the following article, I’m going to discuss 5 concepts that will bring your React skills and knowledge to the next level.</p><p>If you’re completely new to React, take some time to complete <a href="https://reactjs.org/tutorial/tutorial.html">this tutorial</a> and come back after!</p><h3>1. <a href="https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops">The Component Lifecycle</a></h3><p>By far the most important concept on this list is understanding the component lifecycle. The component lifecycle is exactly what it sounds like: it details the life of a component. Like us, components are born, do some things during their time here on earth, and then they die</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*IjuueoY_KFPK5VXA.png" /></figure><p>Let’s break this image down. Each colored horizontal rectangle represents a lifecycle method (except for “React updates DOM and refs”). The columns represent different <em>stages</em> in the components life.</p><p>A component can only be in one stage at a time. It starts with mounting and moves onto updating. It stays updating perpetually until it gets removed from the virtual DOM. Then it goes into the unmounting phase and gets removed from the DOM.</p><p>The lifecycle methods allow us to run code at specific points in the component’s life or in response to changes in the component’s life.</p><p>Let’s go through each stage of the component and the associated methods.</p><h4>Mounting</h4><p>Since class-based components are classes, hence the name, the first method that runs is the constructor method. Typically, the constructor is where you would initialize component state.</p><p>Next, the component runs the getDerivedStateFromProps. I’m going to skip this method since it has limited use.</p><p>Now we come to the render method which returns your JSX. Now React “mounts” onto the DOM.</p><p>Lastly, the componentDidMount method runs. Here is where you would do any asynchronous calls to databases or directly manipulate the DOM if you need. Just like that, our component is born.</p><h4>Updating</h4><p>This phase is triggered every time state or props change. Like in mounting, getDerivedStateFromProps is called (but no constructor this time!).</p><p>Next shouldComponentUpdate runs. Here you can compare old props/state with the new set of props/state. You can determine if your component should re-render or not by returning true or false. This can make your web app more efficient by cutting down on extra re-renders. If shouldComponentUpdate returns false, this update cycle ends.</p><p>If not, React re-renders and getSnapshotBeforeUpdate runs afterwards. This method has limited use as well. React then runs componentDidUpdate. Like componentDidMount you can use it to make any async calls or manipulate the DOM.</p><h4>Unmounting</h4><p>Our component lived a good life, but all good things must come to an end. The unmounting phase is that last stage of the component lifecycle. When you remove a component from the DOM, React runs componentWillUnmount right before it gets removed. You should use this method to clean up any open connections such as WebSockets or intervals.</p><h4>Other Lifecycle Methods</h4><p>Before we move onto the next topic, let’s briefly talk about forceUpdate and getDerivedStateFromError.</p><p>forceUpdate is a method that directly causes a re-render. While there may be a few use cases for it, it should typically be avoided.</p><p>getDerivedStateFromError on the other hand is a lifecycle method that isn’t directly part of the component lifecycle. In the event of an error in a component, getDerivedStateFromError runs and you can update state to reflect that an error occurred. Use this method copiously.</p><p>The following <a href="https://codepen.io/chrischuck/pen/EdrBxW"><strong>CodePen snippet</strong></a> shows the steps in the mounting phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*-djQiujJnoBByVLT.png" /></figure><p>Understanding React’s component lifecycle and methods will allow you to maintain proper data flow and handle events in your application.</p><h3>2. <a href="https://reactjs.org/docs/higher-order-components.html">Higher-Order Components</a></h3><p>You may have used higher-order components, or HOCs, already. Redux’s connect function, for example, is a function that returns a HOC. But what exactly is a HOC?</p><p>From the React docs:</p><blockquote><em>A higher-order component is a function that takes a component and returns a new component.</em></blockquote><blockquote>Going back to Redux’s connect function, we can look at the following code snippet:</blockquote><pre>const hoc = connect(state =&gt; state)const WrappedComponent = hoc(SomeComponent)</pre><p>When we call connect, we get a HOC back that we can use to wrap a component. From here we just pass our component to the HOC and start using the component our HOC returns.</p><p>What HOCs allow us to do is abstract shared logic between components into a single overarching component.</p><p>A good use case for an HOC is authorization. You could write your authentication code in every single component that needs it. It would quickly and unnecessarily bloat your code.</p><p>Let’s look at how you might do auth for components without HOCs:</p><p>Using HOCs, you might do something like so:</p><p>Here’s a working <a href="https://codepen.io/chrischuck/pen/yRwMeo"><strong>CodePen snippet</strong></a> for the above code.</p><p>Looking at the above code, you can see we are able to keep our regular components very simple and “dumb” while still providing authentication for them. The AuthWrapper component lifts all authentication logic into a unifying component. All it does is take a prop called isLoggedIn and returns the WrappedComponent or a paragraph tag based on whether or not that prop is true or false.</p><p>As you can see, HOCs are extremely useful because they let us reuse code and remove bloat. We’ll get more practice with these soon!</p><h3>3. <a href="https://reactjs.org/docs/state-and-lifecycle.html">React State and setState()</a></h3><p>Most of you have probably used React state, we even used it in our HOC example. But it’s important to understand that when there’s a state change, React will trigger a re-render on that component (unless you specify in shouldComponentUpdate to say otherwise).</p><p>Now let’s talk about how we change state. The only way you should change state is via the setState method. This method takes an object and merges it into the current state. On top of this, there are a few things you should also know about it.</p><p>First, setState is asynchronous. This means state won’t update exactly after you call setState and this can lead to some aggravating behavior which we will hopefully now be able to avoid!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*lBIyglF-U_WrB2bf.png" /></figure><p>Looking at the above image, you can see that we call setState and then console.log state right after. Our new counter variable <em>should </em>be 1, but it’s in fact 0. So what if we want to access the new state after setState actually updates state?</p><p>This brings us to the next piece of knowledge that we should know about setState and that is it can take a callback function. Let’s fix our code!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*8WZRQKnu5Z62CQA5.png" /></figure><p>Great, it works, now we’re done right? Not exactly. We’re actually not using setState correctly in this case. Instead of passing an object to setState, we’re going to give it a function. This pattern is typically used when you’re using the current state to set the new state, like in our example above. If you’re not doing that, feel free to keep passing an object to setState. Let’s update our code again!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Ko8FekpUJ4Tbq4wz.png" /></figure><p>Here’s the <a href="https://codepen.io/chrischuck/pen/wYYxrd"><strong>CodePen</strong></a> for the above setState code.</p><p>What’s the point of passing a function instead of an object? Because setState is asynchronous, relying on it to create our new value will have some pitfalls. For example, by the time setState runs, another setState could have mutated state. Passing setState a function gives us two benefits. The first is it allows us to take a static copy of our state that will never change on its own. The second is that it will queue the setState calls so they run in order.</p><p>Just take a look at the following example where we try to increment the counter by 2 using two consecutive setState calls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*PfkrTGc_EyprJ_5-.png" /></figure><p>The above is what we saw earlier while we have the fix below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*iOnTy1taj5MGjHDv.png" /></figure><p><a href="https://codepen.io/chrischuck/pen/GYemvM"><strong>CodePen</strong></a> for above code.</p><p>In the first picture, both setState functions directly use this.state.counter and as we learned earlier, this.state.counter will still be zero after the first setState is called. Thus, we get 1 instead of 2 because <em>both</em><strong><em> </em></strong>setState functions are setting counter to 1.</p><p>In the second picture, we pass setState a function which will guarantee both setState functions run in order. On top of this, it takes a snapshot of state, rather than using the current, un-updated state. Now we get our expected result of 2.</p><p>And that’s all you need to know about React state!</p><h3>4. <a href="https://reactjs.org/docs/context.html">React Context</a></h3><p>This brings us now to React context which is just global state for components.</p><p>The React context API allows you to create global context objects that can be given to any component you make. This allows you to share data without having to pass props down all the way through the DOM tree.</p><p>So how do we use context?</p><p>First create a context object:</p><p>const ContextObject = React.createContext({ foo: &quot;bar&quot; })</p><p>The React docs describe setting context in a component like so:</p><p>MyClass.contextType = MyContext;</p><p>However, in CodePen (React 16.4.2), this did not work. Instead, we’re going to use an HOC to consume context in a similar manner to what Dan Abramov <a href="https://github.com/facebook/react/issues/12397#issuecomment-375501574">recommends</a>.</p><p>What we are doing is wrapping our component with the Context.Consumer component and passing in context as a prop.</p><p>Now we can write something like the following:</p><p>And we’ll have access to foo from our context object in props.</p><p>How do we change context you might ask. Unfortunately, it’s a little more complicated but we can use an HOC again and it might look like this:</p><p>Let’s step through this. First, we take the initial context state, the object we passed to React.createContext() and set it as our wrapper component’s state. next we define any methods we’re going to use to change our state. Lastly, we wrap our component in the Context.Provider component. We pass in our state and function to the value prop. Now any children will get these in context when wrapped with the Context.Consumer component.</p><p>Putting everything together (HOCs omitted for brevity):</p><p>Now our child component has access to global context. It has the ability to change the foo attribute in state to baz.</p><p>Here’s a link to the full <a href="https://codepen.io/chrischuck/pen/jeJLZG?editors=0011"><strong>CodePen</strong></a><strong> </strong>for the context code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d31156d759c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React 5 Advanced Topics]]></title>
            <link>https://amitt6580.medium.com/react-5-advanced-topics-ffed5245b926?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffed5245b926</guid>
            <category><![CDATA[chetu]]></category>
            <category><![CDATA[react-developer]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <category><![CDATA[developer-community]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Sat, 01 May 2021 22:51:43 GMT</pubDate>
            <atom:updated>2021-05-01T22:51:43.803Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lazyloading</h3><p>Code-Splitting is a feature supported by bundlers like Webpack, Rollup and Browserify (via factor-bundle) which can create multiple bundles that can be dynamically loaded at runtime.</p><p>How to do it:</p><p><em>To functions doing dynamic imports:</em></p><pre>import(&quot;./math&quot;).then(math =&gt; {<br>  console.log(math.add(16, 26));<br>});</pre><p><em>Or to components using React.Lazy:</em></p><pre>const OtherComponent = React.lazy(() =&gt; import(&#39;./OtherComponent&#39;))</pre><p>This will automatically load the bundle containing the OtherComponent when this component is first rendered.<br>The lazy component should then be rendered inside a Suspense component, which allows us to show some fallback content (such as a loading indicator) while we’re waiting for the lazy component to load.</p><pre>const OtherComponent = React.lazy(() =&gt; import(&#39;./OtherComponent&#39;));<br>const AnotherComponent = React.lazy(() =&gt; import(&#39;./AnotherComponent&#39;));function MyComponent() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>        &lt;section&gt;<br>          &lt;OtherComponent /&gt;<br>          &lt;AnotherComponent /&gt;<br>        &lt;/section&gt;<br>      &lt;/Suspense&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Webworkers</h3><p>Web Workers makes it possible to run a script operation in a background thread separate from the main execution thread of a web application. The advantage of this is that laborious processing can be performed in a separate thread, allowing the main (usually the UI) thread to run without being blocked/slowed down.</p><pre>var w;<br>function startWorker() {<br> if (typeof(Worker) !== &quot;undefined&quot;) {<br> if (typeof(w) == &quot;undefined&quot;) {<br> w = new Worker(&quot;demo_workers.js&quot;);<br> }<br> w.onmessage = function(event) {<br> document.getElementById(&quot;result&quot;).innerHTML = event.data;<br> };<br> } else {<br> document.getElementById(&quot;result&quot;).innerHTML = &quot;Sorry! No Web Worker support.&quot;;<br> }<br>}<br>function stopWorker() {<br> w.terminate();<br> w = undefined;<br>}</pre><h3><strong>IndexDB</strong></h3><p>IndexDB is a built-in database, much more powerful than localStorage.<br>Key/value storage: value can be (almost) anything, multiple key types.<br>Supports transactions for reliability.<br>Supports key range queries, indexes.<br>Can store much more data than localStorage.</p><p><a href="https://gist.github.com/cauerego/7b0001989b78977d0ce4#file-indexeddb101-js">Here a sample</a>.</p><p><strong>Token, cookies, and JWT</strong></p><p>To make the authentication token process we need to get two tokens: the access token and the session token.<br>The access token is our main key to persist auth status. It just gives us access to receive the session token. The session token expires after a time at backend part. When this happens we need to make a new request with the access token to refresh the session token. Usually the code that the server send is 401 unauthorized.</p><p>With cookies this process is easier. you set the headers to contain “credentials” and it take the hidded cookies. They should be set as ont changeable by JS scripts and chrome hiddes it from cookies tab.</p><p><strong>Bonus:</strong> If you have CORS problems to access the server you should use the properties access-control-allow-origin and/or access-control-allow-headers.</p><p>JSON Web Tokens (JWTs) make it easy to send read-only signed “claims” between services (both internal and external to your app/site). Claims are any bits of data that you want someone else to be able to read and/or verify but not alter.</p><h3>Performance checkers</h3><ul><li>Audits: Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, and more.</li><li>Redux devtools: Redux DevTools for debugging application’s state changes.</li><li>React devtools: It allows you to inspect the React component hierarchies in the Chrome Developer Tools. You will get two new tabs in your Chrome DevTools: “⚛️ Components(to look into your components tree)” and “⚛️ Profiler(to make performance test in each component)”. It also says how many renders your component did.</li><li>Performance devtools: It is a tab of devtools that you can check the general performance of your application. Network devtools: You can check a list of all requests, and track the time they are taking to resolve. why-this-render: lib to check the quantity of components renderization.</li><li>Renderer devtools: It is an option at console options on devtools that you ca track some info about the rendering. One of them is FPS that checks how fluid is your page, the best value to FPS is at 60. So, if is lower than that that means you have space to work on performance.</li></ul><p><em>Bonus articles:</em><br><a href="https://developers.google.com/web/tools/chrome-devtools/evaluate-performance">Devtools</a>, <a href="https://reactjs.org/docs/optimizing-performance.html">React Performance</a> and <a href="https://reactjs.org/docs/profiler.html">Profiler</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffed5245b926" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Laravel: 13 Topics and Links to Learn Them]]></title>
            <link>https://amitt6580.medium.com/advanced-laravel-13-topics-and-links-to-learn-them-a1221794c2e5?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1221794c2e5</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[chetu]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <category><![CDATA[laravel-development]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Sat, 01 May 2021 22:22:02 GMT</pubDate>
            <atom:updated>2021-05-01T22:22:02.301Z</atom:updated>
            <content:encoded><![CDATA[<p>Quite often I get a question from junior developers like “how to get better at Laravel”, and there’s so much to study potentially that I decided to gather the topics and classify them somehow. Let’s begin.</p><h3>Topic 1. Sending emails and notifications</h3><p>It seems like a topic for basic Laravel developer, but while it’s easy to send emails, but the whole system of various <strong>notifications</strong> is much deeper, and worth studying. Sub-topics:</p><ul><li>Sending <a href="https://laravel.com/docs/5.8/notifications">Laravel notifications</a> (not only email, but also <a href="https://laravel.com/docs/5.8/notifications#slack-notifications">Slack</a>, <a href="https://laravel.com/docs/5.8/notifications#sms-notifications">SMS</a> etc);</li><li>Email templates — <a href="https://laraveldaily.com/mail-notifications-customize-templates/">customization</a>, <a href="https://laravel.com/docs/5.8/mail#writing-markdown-messages">Markdown messages</a>;</li><li>Putting emails <a href="https://laravel.com/docs/5.8/mail#queueing-mail">into queue</a> (<em>more on that later</em>);</li><li>Using external services to send emails — <a href="https://laravel.com/docs/5.8/mail#driver-prerequisites">Mailgun</a>, <a href="https://laraveldaily.com/send-mailchimp-email-campaigns-from-laravel/">Mailchimp</a> etc.</li></ul><h3>Topic 2. Queues and Jobs</h3><p>Modern web-applications are much more than just browser-based synchronous page rendering, a lot of stuff is happening in the background on the server, while user may not even be online. So queues are getting more and more vital to learn. Also, there are a few tools related to the queues mechanism.</p><p>Sub-topics and links:</p><ul><li>Laravel Queues and Jobs <a href="https://laravel.com/docs/5.8/queues">official documentation;</a></li><li><a href="https://laravel.com/docs/5.8/horizon">Laravel Horizon</a> — dashboard to monitor queues;</li><li><a href="https://redis.io/">Redis</a> — most popular driver to use for queues (you need to be able to install and configure it);</li><li><a href="https://laraveldaily.teachable.com/courses/how-to-structure-laravel-project/lectures/8760303">Jobs, Queues and Scheduling Tasks</a> — my video from the course “How to Structure Laravel Project”;</li><li><a href="https://dev.to/radpangolin/demystifying-laravel-queues-2ec3">Demystifying Laravel Queues</a> — article on Dev.to.</li></ul><p><strong>Side note</strong>: Jobs may be not queue-able and just run whenever you ask them, maybe even in sync mode, but it may be a good practice to structure your project code into Jobs, for clarity.</p><h3>Topic 3. Advanced Eloquent and DB Operations</h3><p>Eloquent is a great Laravel mechanism to deal with the database, but there’s so many less-known functions under the hood, like: Observers, Accessors/Mutators, Seeding, “magic methods” like firstOrCreate(), Collections etc.</p><p>Sub-topics and links:</p><ul><li><a href="https://laraveldaily.teachable.com/p/laravel-eloquent-expert-level">Eloquent: Expert Level</a> — my course on the topic;</li><li><a href="https://quickadminpanel.com/blog/eloquent-relationships-the-ultimate-guide/">Eloquent Relationships: The Ultimate Guide</a>;</li><li><a href="https://laravel.com/docs/5.8/eloquent#observers">Model Observers</a> — official documentation;</li><li><a href="https://laravel.com/docs/5.8/eloquent-mutators">Accessors and Mutators</a> — official documentation;</li><li><a href="https://laracasts.com/series/laravel-from-scratch-2018/episodes/35">Collection Essentials</a> — video from Laracasts.</li></ul><h3>Topic 4. Advanced Error/Exception Managing and Preventing</h3><p>Bugs happen everyday, and that’s normal. But you can do a lot of things to prevent them or help the team to fix them easier. Using try-catch blocks, creating exceptions, configuring logging parameters, using tools like Bugsnag/Rollbar/Sentry, sending bug notifications to Slack/email etc.</p><p>Sub-topics and links:</p><ul><li><a href="https://laraveldaily.com/how-to-catch-handle-create-laravel-exceptions/">Laravel Exceptions: How to Catch, Handle and Create Your Own</a>;</li><li><a href="https://laraveldaily.com/laravel-api-errors-and-exceptions-how-to-return-responses/">Laravel API Errors and Exceptions: How to Return Responses</a>;</li><li><a href="https://stackify.com/php-try-catch-php-exception-tutorial/">PHP Try Catch: Basics &amp; Advanced PHP Exception Handling Tutorial</a>;</li><li><a href="https://laravel.com/docs/master/errors">Laravel Error Handling</a> — official documentation.</li></ul><h3>Topic 5. Creating Artisan Commands</h3><p>We all probably use commands like “<em>php artisan migrate</em>” or “<em>php artisan make:model</em>“, but it’s often useful to create your own command, and potentially put it as a job into queue (see Topic 2 above).</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/artisan#writing-commands">Writing Artisan Commands</a> — official documentation;</li><li><a href="https://quickadminpanel.com/blog/list-of-16-artisan-make-commands-with-parameters/">List of 16 artisan make:XXXX Commands with Parameters</a>;</li><li><a href="https://laravel-news.com/custom-artisan-commands">Writing Custom Laravel Artisan Commands</a> — article from Laravel News.</li></ul><h3>Topic 6. APIs: Resources, Auth and Passport</h3><p>This one is pretty huge — the whole world is going API, and you need to learn it. A while ago I would recommend learning Lumen, but now it lost popularity and performance advantage over main Laravel.</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/eloquent-resources">Eloquent: API Resources </a>— official documentation;</li><li><a href="https://www.toptal.com/laravel/restful-laravel-api-tutorial">Laravel API Tutorial: How to Build and Test a RESTful API</a> — article from Toptal;</li><li><a href="https://blog.pusher.com/build-rest-api-laravel-api-resources/">Build a REST API with Laravel API resources</a> — article from Pusher;</li><li><a href="https://laravel.com/docs/5.8/api-authentication">Laravel API Authentication</a> — official documentation;</li><li><a href="https://laravel.com/docs/5.8/passport">Laravel Passport</a> — official documentation;</li><li><a href="https://laraveldaily.com/laravel-api-errors-and-exceptions-how-to-return-responses/">Laravel API Errors and Exceptions: How to Return Responses</a>.</li></ul><h3>Topic 7. Events and Listeners</h3><p>Small topic, representing one of the design patterns in Laravel. You can fire an event, and have a separate class “listening” for when it happens.</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/events">Laravel Events</a> — official documentation;</li><li><a href="https://code.tutsplus.com/tutorials/custom-events-in-laravel--cms-30331">Custom Events in Laravel</a> — article from TutsPlus.</li></ul><h3>Topic 8. Payments and Cashier</h3><p>If you work on any serious project, probably some kind of payment will be involved. There are various payment methods/gateways, depending on the world region you’re in, but I would recommend to learn handling Stripe anyway, even if you don’t use it in production.</p><p>Sub-topics and links:</p><ul><li><a href="https://quickadminpanel.com/blog/stripe-payments-in-laravel-the-ultimate-guide/">Stripe Payments in Laravel: The Ultimate Guide</a>;</li><li><a href="https://quickadminpanel.com/blog/paypal-payments-in-laravel-the-ultimate-guide/">PayPal payments in Laravel: The Ultimate Guide</a>;</li><li><a href="https://laravel.com/docs/5.8/billing">Laravel Cashier</a> — official documentation;</li><li><a href="https://laravel.com/docs/5.8/braintree">Laravel Cashier (Braintree)</a> — official documentation.</li></ul><h3>Topic 9. Automated Testing, TDD and Dusk</h3><p>This is a hot topic, with constant debates around it. Should we do unit testing? Should we do TDD? (<em>test-driven development</em>) What kind of tests do we write? How to make them run smoothly?</p><p>My personal take is that you have to have <strong>some</strong> automated tests, for the <strong>crucial</strong> parts of your application — especially related to money transactions, or main authentication. Basically, test everything that would make you lose your job, if it fails. Testing everything else — not a priority.</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/testing">Laravel Testing: Getting Started</a> — official documentation;</li><li><a href="https://course.testdrivenlaravel.com/">Test-Driven Laravel</a> — awesome course by Adam Wathan, highly recommended;</li><li><a href="https://laravel.com/docs/5.8/dusk">Laravel Dusk</a> — official documentation;</li><li><a href="https://laracasts.com/series/build-a-laravel-app-with-tdd">Build A Laravel App With TDD</a> — Laracasts Series;</li><li><a href="https://medium.freecodecamp.org/how-to-build-a-laravel-rest-api-with-test-driven-development-c4bb6417db3c">How to build a Laravel REST API with Test-Driven Development</a> — article from freeCodeCamp;</li><li><a href="https://medium.com/@jsdecena/simple-tdd-in-laravel-with-11-steps-c475f8b1b214">Simple TDD in Laravel with 11 steps</a> — article from Medium.</li></ul><h3>Topic 10. Deployment to Servers and Continuous Integration</h3><p>Related to the previous topic — part of the deployment of your features, you should run your automated tests on some kind of staging server, and ideally set it up to run automatically.</p><p>Some of this knowledge isn’t specific to Laravel — you need to know how to set up and configure a new server (or use tools for it), how to do git branching and how to push your code correctly (especially if you work in a team), how to do zero-time deployment, rollback if something happens etc.</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/deployment">Laravel Deployment</a> — official documentation;</li><li><a href="https://laraveldaily.com/how-to-deploy-laravel-projects-to-live-server-the-ultimate-guide/">How to Deploy Laravel Projects to Live Server: The Ultimate Guide</a>;</li><li><a href="https://forge.laravel.com/">Laravel Forge</a> — tool to create/provision new servers for Laravel in minutes (and see my video <a href="https://www.youtube.com/watch?v=dzD7HI5lI1M">DEMO: New Server and Deployment with Laravel Forge)</a>;</li><li><a href="https://envoyer.io/">Envoyer.io</a> — zero-time PHP deployment, official tool by Laravel (again, my video — <a href="https://www.youtube.com/watch?v=hf0_pU-hRUE">How to Deploy Laravel Project with Envoyer</a>);</li><li><a href="https://medium.freecodecamp.org/laravel-continuous-deployment-with-circleci-and-deployer-c70b27fa70d2">Laravel Continuous Deployment With CircleCI and Deployer</a>.</li></ul><h3>Topic 11. Package Development</h3><p>At some point you grow a few projects that may require the same functionality, so it makes sense to turn it into a package, and maybe release it as open-source.</p><p>Sub-topics and links:</p><ul><li><a href="https://phppackagedevelopment.com/">PHP Package Development</a> — course by Marcel Pociot;</li><li><a href="https://www.youtube.com/watch?v=ivrc1ZKFgHI&amp;list=PLpzy7FIRqpGBQ_aqz_hXDBch1aAA-lmgu">Laravel Package Development</a> — video course on YouTube;</li><li><a href="https://laravel.com/docs/5.8/packages">Package Development</a> — official documentation.</li></ul><h3>Topic 12. Laravel Scout Search and Algolia</h3><p>If you’re dealing with text-based search in a big database (like products in e-shop), you would definitely use a search mechanism like Laravel Scout. There are multiple drivers for it, I personally use Algolia and their free plan is more than sufficient for small projects.</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/scout">Laravel Scout</a> — official documentation;</li><li><a href="https://www.algolia.com/doc/framework-integration/laravel/tutorials/getting-started-with-laravel-scout-vuejs/">Getting started with Laravel Scout and Vue Instant Search</a> — article from Algolia;</li><li><a href="https://appdividend.com/2018/05/15/laravel-scout-search-tutorial-with-example/">Laravel Scout Algolia Search Tutorial With Example</a>.</li></ul><h3>Topic 13. Socialite and OAuth</h3><p>If you’ve ever seen a button “Login with Facebook” or “Sign in with Google”, it is usually powered by OAuth protocol, and its implementation tool in Laravel is called Socialite. Pretty easy to install and configure, and valuable to learn.</p><p>Sub-topics and links:</p><ul><li><a href="https://laravel.com/docs/5.8/socialite">Laravel Socialite</a> — official documentation;</li><li><a href="https://laraveldaily.com/from-google-api-to-google-sign-in-with-laravel-socialite/">From Google+ API to Google Sign In with Laravel Socialite</a>;</li><li><a href="https://www.twilio.com/blog/add-facebook-twitter-github-login-laravel-socialite">Add Facebook, Twitter, and GitHub Login To Laravel with Socialite</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1221794c2e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Covid19]]></title>
            <link>https://amitt6580.medium.com/covid19-59427f697d2f?source=rss-b6a666c54702------2</link>
            <guid isPermaLink="false">https://medium.com/p/59427f697d2f</guid>
            <category><![CDATA[instagram]]></category>
            <category><![CDATA[wfh]]></category>
            <category><![CDATA[covid-update]]></category>
            <category><![CDATA[inspiration]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Amit Tyagi]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 09:17:22 GMT</pubDate>
            <atom:updated>2021-04-29T09:17:22.205Z</atom:updated>
            <content:encoded><![CDATA[<p>If COVID-19 is spreading in your community, stay safe by taking some simple precautions, such as physical distancing, wearing a mask, keeping rooms well ventilated, avoiding crowds, cleaning your hands, and coughing into a bent elbow or tissue. Check local advice where you live and work. <strong>Do it all!</strong></p><p>You also find out more about WHO’s recommendations for getting vaccinated on our <a href="https://www.who.int/emergencies/diseases/novel-coronavirus-2019/covid-19-vaccines/advice">public advice</a> page on COVID-19 vaccines.</p><p><strong>What to do to keep yourself and others safe from COVID-19</strong></p><ul><li><strong>Maintain at least a 1-metre distance between yourself and others </strong>to reduce your risk of infection when they cough, sneeze or speak. Maintain an even greater distance between yourself and others when indoors. The further away, the better.</li><li><strong>Make wearing a mask a normal part of being around other people. The appropriate use, storage and cleaning or disposal are essential to make masks as effective as possible.</strong></li></ul><p>Here are the basics of <a href="https://youtu.be/ciUniZGD4tY">how to wear a mask</a>:</p><ul><li>Clean your hands before you put your mask on, as well as before and after you take it off, and after you touch it at any time.</li><li>Make sure it covers both your nose, mouth and chin.</li><li>When you take off a mask, store it in a clean plastic bag, and every day either wash it if it’s a fabric mask, or dispose of a medical mask in a trash bin.</li><li>Don’t use masks with valves.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59427f697d2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>