<?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 Pranav Bhatia on Medium]]></title>
        <description><![CDATA[Stories by Pranav Bhatia on Medium]]></description>
        <link>https://medium.com/@programmercouple-pranav?source=rss-710bfdad0433------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*56WRduemSb7K5dF5Lm31EQ.jpeg</url>
            <title>Stories by Pranav Bhatia on Medium</title>
            <link>https://medium.com/@programmercouple-pranav?source=rss-710bfdad0433------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:26:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@programmercouple-pranav/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[Firebase Cloud Functions 101: Creating serverless app in 5 minutes]]></title>
            <link>https://programmercouple-pranav.medium.com/firebase-cloud-functions-101-creating-serverless-app-in-5-minutes-fab1137b1ced?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/fab1137b1ced</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Sat, 11 Feb 2023 21:13:49 GMT</pubDate>
            <atom:updated>2023-02-11T21:27:38.732Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HteDHZu3OQYbv4sK.png" /></figure><p>Have you ever wanted to add some extra cool features to your application but don’t want the hassle of managing service or infrastructure? Well meet Firebase Cloud Functions, and it allows you to run your backend code without worrying at all about the infrastructure behind it.</p><p>In simple words, it’s a service from Google that would easily allow you to run code on certain events like <strong>a new user signup</strong> or <strong>a database change in your application</strong>.</p><blockquote><em>You can write basic functions with javascript and Firebase Function will take care of everything in terms of deployment and scaling without you having to worry about it.</em></blockquote><p>So you can easily add cool features like processing images or sending push notifications without worrying about the technical details.</p><p>Let’s try it out right away, and I’m sure you’ll be impressed. My goal for this article to help you is to create a cloud function from scratch in less than five minutes.</p><p>We’ll start with a basic Hello-World application.</p><p>We’ll do a firebase init, which will initialize our application with no code in the beginning, we&#39;ll deploy it and even test it out by invoking the API call that we&#39;ll create. So let&#39;s get into the code right away.</p><blockquote><em>Two prerequisites for this are:</em></blockquote><ul><li>Have an account on Firebase.</li><li>Switch to a paid account, which is also known as <strong>Blaze Plan</strong>.</li></ul><p>However, don’t worry about getting any bills or spending actual money. Wondering why? See the pricing policy below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JuA0dGX0MDc5W7-r.png" /></figure><p>So up to 2 million requests a month. It’s free. You actually only need to pay if your request exceeds 2 million a month. I’m sure you won’t go over 2 million unless you’re creating a huge application that’s very popular (and that’s a good problem to have).</p><p>Now, open up your code editors and the first thing you need to do is run this command:</p><pre>npm install -g firebase-tools</pre><p>This will install all the necessary Firebase libraries that you need in order to run the Firebase commands on your terminal or command line.</p><p>The next thing we need to do is run</p><pre>firebase login</pre><p>This will ask for your credentials and then log us into our Firebase account. This is where the fun begins.</p><p>Now we have to run:</p><pre>firebase init</pre><p>which will actually initialize our Firebase project, and it’ll ask us, what services would we like to use, select “Function”. Follow the next few simple steps and your project setup is now complete.</p><p>Here are a few screenshots of my setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TpWfWaBDKcQlTYQT.png" /><figcaption>Project Setup 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LlBDs5kN0NtnQL9fFpOrRw.png" /><figcaption>Project Setup 2</figcaption></figure><p>Once the setup is completed, you will notice a functions folder. In this folder, we have a <strong>package.json</strong> file, a <strong>node_modules</strong> folder, and the <strong>index.js</strong> file (this is where the code lies).</p><blockquote><strong><em>index.js</em></strong><em> is the heart of our application</em></blockquote><p>Start with this import:</p><pre>const functions = require(&quot;firebase-functions&quot;);</pre><p>The “firebase init” command took care of installing all the dependencies, including <strong>firebase-functions</strong>.</p><p>Create an actual firebase function now with just 2 lines of code next:</p><pre>exports.helloFunction = functions.https.onRequest((req, res) =&gt; { <br>    // your code goes here <br>});</pre><p>So whatever function you <strong>export</strong> here, will be the name of the Firebase function that is actually called when invoked, which is essentially a serverless application. This function can have hundreds of lines of code doing complicated tasks, or simply a “hello world” application.</p><pre>exports.helloFunction = functions.https.onRequest((req, res) =&gt; {<br>    res.json(&quot;Hello World from a serverless application.&quot;) <br>});</pre><p>All we are doing is just returning a response in JSON format, which will contain a message. Now you must be thinking “how to actually deploy this function”, right? Is it very complicated? The answer is not at all.</p><p>I just have to run this command:</p><pre>fireplace deploy --only functions</pre><p>That’s it. We have successfully deployed. Congratulations!</p><blockquote><em>Your API is enabled and soon it’s going to register a REST-API with “helloFunction” as an endpoint.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qAZh7n2tWXXDvQE1.png" /></figure><p>You have created your very own Firebase Function. You can simply test it out using Postman.</p><p>I am amazed to see how simple it is to create a serverless application today.</p><blockquote>My mind was blown the first time I did this because I used to think serverless applications are a mystery and they must be complicated. We all have heard about the AWS Lambda function, which is essentially the same thing, but by Amazon and Firebase-Functioin is by Google.</blockquote><p>I hope you also have bridged the gap of knowledge today in order to launch a first-ever serverless application or a firebase function in this particular case, and I hope this will encourage you to create your own (and much better) applications.</p><p>Obviously, this is just a hello function, but as I said, if you want to learn more about Firebase Functions, check out our YouTube tutorial videos:</p><ol><li><a href="https://www.youtube.com/watch?v=VLZqpOFrlFM">CRON Job With Firebase Functions — Complete Tutorial</a></li><li><a href="https://www.youtube.com/watch?v=TCdi8wSt64g">Learn Firebase Functions: Asking ChatGPT To Create My First Serverless Application</a></li></ol><p>Also, feel free to ask your questions. We try to reply to the majority of comments that we get on our articles/videos.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJmBRuX68r5M%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJmBRuX68r5M&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJmBRuX68r5M%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fed996f3a9af7f908a52b346fd0cffbb/href">https://medium.com/media/fed996f3a9af7f908a52b346fd0cffbb/href</a></iframe><p><em>Originally published at </em><a href="https://askillaway.substack.com/p/firebase-cloud-functions-101?sd=pf"><em>https://askillaway.substack.com</em></a><em> on February 11, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fab1137b1ced" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Explained in 1 Minute]]></title>
            <link>https://programmercouple-pranav.medium.com/best-and-simplest-explanation-of-devops-3b2c9732ae32?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b2c9732ae32</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Wed, 28 Dec 2022 06:41:13 GMT</pubDate>
            <atom:updated>2023-01-26T13:55:49.693Z</atom:updated>
            <content:encoded><![CDATA[<p>DevOps Explained in 1 Minute</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*9btCuXEuMly0rFEGS7bmpg.jpeg" /></figure><p>Really, DevOps is about how you take your existing functions of who is building the application, and who’s operating the application. In a small company, those might be the same people, and how you empower them to build the software better and operate it more reliably. We really should be focused on what practices you can implement to make the lives of the technical team members who are building and operating this application better and reduce the manual toil that they have to go through in their day-to-day process.</p><p><a href="https://www.youtube.com/shorts/Vz5ODWk1W08">Best and Simplest Explanation of DevOps @DevOpsDirective</a></p><p><em>Originally published at </em><a href="https://www.theimmigrantprogrammers.com/p/best-and-simplest-explanation-of"><em>https://www.theimmigrantprogrammers.com</em></a><em> on December 28, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b2c9732ae32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Will Monorepos Make a Comeback?]]></title>
            <link>https://programmercouple-pranav.medium.com/will-monorepos-make-a-comeback-78009ee958b8?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/78009ee958b8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Sun, 18 Dec 2022 15:00:56 GMT</pubDate>
            <atom:updated>2022-12-28T04:42:53.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0wSNeJDZaMQBzdot" /></figure><p>So a company called NX wants to take monorepo’s mainstream, and they recently got 8.6 million in seed funding. It’s not like any other new company. It’s actually founded by ex-Google employees and a lot of angel investors were jumping right into it, including one of the co-founders of GitHub.</p><p>Now, this might come as a surprise to a lot of developers like you and me because, in the last 10–15 years, there was a movement of moving away from mono repositories and moving towards microservices. Small projects, a project that handles one single system in your architecture, right? And this company, including a lot of angel investors, now believes that mono repositories are the way to go in the future.</p><p>What do you think about it?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBwVSRrdQ9QM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBwVSRrdQ9QM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBwVSRrdQ9QM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8032927d55bad5af38f49e3107a10ccc/href">https://medium.com/media/8032927d55bad5af38f49e3107a10ccc/href</a></iframe><p><em>Originally published at </em><a href="https://www.theimmigrantprogrammers.com/p/will-monorepos-make-a-comeback"><em>https://www.theimmigrantprogrammers.com</em></a><em> on December 18, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78009ee958b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google is a Monorepo!]]></title>
            <link>https://programmercouple-pranav.medium.com/google-is-a-monorepo-b7c5b32119d8?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7c5b32119d8</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Sat, 17 Dec 2022 16:43:10 GMT</pubDate>
            <atom:updated>2023-01-02T03:01:45.132Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xDRIj3nsJX6lvUD-" /><figcaption>Photo by <a href="https://unsplash.com/@rajeshwerbatchu7?utm_source=medium&amp;utm_medium=referral">Rajeshwar Bachu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A lot of developers have a misconception and they believe that ,onorepos are gone and monorepos are not good for big companies.</p><p>They say that each project and each repository should be small with small lines of code and handle one particular thing in their whole company or their whole project.</p><p>But do you know who has the biggest monorepo in the whole world? <strong>It’s Google.</strong></p><p>At Google, they have one mono repo that has more than 86 terabytes of data, more than 2 billion lines of code, and more than 9 million source files.</p><p>So think again before you rule out monorepos for your project.</p><p><a href="https://www.youtube.com/shorts/f-qn7nT2dv4">Google is a Monorepo!</a></p><p><em>Originally published at </em><a href="https://www.theimmigrantprogrammers.com/p/google-is-a-monorepo"><em>https://www.theimmigrantprogrammers.com</em></a><em> on December 17, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7c5b32119d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developers — We Need to Stop LYING]]></title>
            <link>https://programmercouple-pranav.medium.com/developers-we-need-to-stop-lying-b72b834059e1?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/b72b834059e1</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 16:08:54 GMT</pubDate>
            <atom:updated>2023-01-08T15:02:24.024Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developers — We Need to Stop LYING</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zvd8B6e1I7cS6blg" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=medium&amp;utm_medium=referral">Sigmund</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello, my fellow programmers. I just want you to stop lying and saying to yourself that I’m going to fix it later.</p><p>You and I both have done so many hacky ways and so many hacky tricks in our code to make things work for today, saying that we will fix it later, but we know that’s never gonna happen, right?</p><p>The number one reason is as time goes on, you lose confidence in your code.</p><p>A lot of developers including me after, you know, 30–35 days of working on something, I don’t remember anything about my previous projects, and especially this becomes a bigger problem when the person who wrote the code leaves the company.</p><p>The second reason is normalization. Now you’re normal to having bad code in your project and it’s no longer an exception.</p><p>Someone said it right: “The longer it remains unchanged, the less likely it is to change in the future” because we are afraid of changing the code. Yes, we know it’s bad, but it works, right?</p><p>So stop lying to yourself and start fixing things when you are working on them the first time.</p><p><a href="https://www.youtube.com/shorts/zzGTxwK9-pk">Developers - We Need to Stop LYING</a></p><p><em>Originally published at </em><a href="https://www.theimmigrantprogrammers.com/p/developers-we-need-to-stop-lying"><em>https://www.theimmigrantprogrammers.com</em></a><em> on December 12, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b72b834059e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alpine.js 101: Understanding the basics]]></title>
            <link>https://javascript.plainenglish.io/alpine-js-101-understanding-the-basics-in-3-minutes-76890650046?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/76890650046</guid>
            <category><![CDATA[alpine]]></category>
            <category><![CDATA[alpinejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Tue, 22 Dec 2020 04:35:40 GMT</pubDate>
            <atom:updated>2020-12-22T08:31:09.906Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qNszrrkyJqIu2O9Y" /><figcaption>Photo by <a href="https://unsplash.com/@maxcodes?utm_source=medium&amp;utm_medium=referral">Maxwell Nelson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We are going to discuss alpine, which can potentially replace libraries like jQuery or even Angular, React, or Vue which you usually use while developing a website.</p><p>If you regularly build sites that require some sprinkling of JavaScript on your UI, to give a better user experience, this article is for you!!</p><blockquote><em>After doing a lot of research and even using it numerous times, I realized that Alpine.js might really be onto something.</em></blockquote><h3>Alpine.js vs others</h3><p>If you have a look at this table, you will actually see the difference in filesize between alpine and other commonly used libraries/frameworks.</p><blockquote><em>Like many other developers, we usually overcomplicate our workflow.</em></blockquote><p>We always choose the latest and most popular libraries. We go to the best libraries we can find online. We see that React, Angular, and Vue have the highest search ranks, and blindly start using them.</p><p>I think that’s a wrong approach because in many cases those libraries are overkill and nothing else.</p><p>I’m not trying to take anything away from frameworks like Angular and React. I actually use them on a day-to-day basis and I actually have all my codebases in angular multiple projects. What I’m trying to say is that there are some websites that don’t need those complex and advanced frameworks, because they really add to the size, and you can actually see this in the table above.</p><h3>When (and when not) to use Alpine</h3><p>If you’re thinking to use Alpine in your next project, let me clear a few things up for you.</p><h4>When to avoid Alpine =&gt;</h4><p>You should NOT reach out for libraries like alpine when your website:</p><ul><li>Have a lot of data manipulations</li><li>Requires enormous validations.</li><li>Have to go through numerous API calls to fetch and process data.</li></ul><p>For these scenarios, I would really really recommend you to use Vue, React, Angular, or any other framework that you’re a fan of.</p><h4>When to use Alpine =&gt;</h4><p>You should only reach out for libraries like alpine when your website:</p><ul><li>Have to do basic manipulation on the DOM.</li><li>Under some conditions, you have to append classes on user interaction</li><li>Listen to some events and alter the UI.</li></ul><p>I think in these scenarios Alpine.js is your best friend.</p><h3>Installation</h3><p><strong>CDN:</strong></p><p>To start, you simply need to add this script tag to the &lt;head&gt;:</p><p>That’s it. It will initialize itself!</p><p><strong>NPM:</strong></p><p>If you prefer installing the package from npm:</p><pre>npm i alpinejs</pre><h3>Creating a basic dropdown</h3><p>Let’s get started with an actual example.</p><p>If we click on this button, the drop-down is visible/open. If we click again, it goes away.</p><blockquote><em>Let’s understand the code now =&gt;</em></blockquote><pre>&lt;div x-data=&quot;{ open: false }&quot;&gt;<br>    &lt;button @click=&quot;open = true&quot;&gt;Open Dropdown&lt;/button&gt; <br>    &lt;ul<br>        x-show=&quot;open&quot;<br>        @click.away=&quot;open = false&quot;<br>    &gt;<br>        Dropdown Body<br>    &lt;/ul&gt;<br>&lt;/div&gt;</pre><p>As you can see in the code, there are some things that come from Alpine, which are not native HTML. For example, x-data, @click, x-show, etc.</p><ul><li><strong>x-data</strong> is basically the data we pass into the component (or div in this case). It has an object that can have some attributes and can even have functions. In this case its {open: false}.</li><li>With the click, using the <strong>@click property</strong> of this button, the variable <strong>open</strong> should be equal to <strong>true</strong>. What happens then? In the background, we have an unordered list which is basically the drop-down body and it becomes visible depending on the value of the <strong>open</strong> variable. So if the open is true, we will actually see the <strong>ul</strong> or the list and whenever we click away from the drop-down body, the variable <strong>open</strong> is assigned a value to be <strong>false</strong>, which then hides the dropdown.</li><li>With the help of <strong>@click.away</strong>, if we click anywhere else on the screen, <strong>open = false </strong>is triggered, hiding the dropdown again!</li></ul><p>So that was pretty simple and you can already see the power of this library.</p><h3>Building a Twitter-style character counter</h3><p>Let’s go through a little more complicated example: let’s build a character counter with alpine.</p><p>In which we basically have a text area and below that, we have the number of characters that can be entered. We’ll allow the users to enter 180 characters and we’ll update the count on every input below the text area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*rMvoevMlnY83IpOaA8t06g.gif" /><figcaption>Final character-counter example</figcaption></figure><blockquote><em>Recommended: Install Alpine IntelliSense for VsCode so that it gives you relevant autocompletes.</em></blockquote><h4>Step 1: Let’s start with the basic skeleton</h4><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br><br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Document&lt;/title&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js&quot; defer&gt;&lt;/script&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>    &lt;div class=&quot;header&quot;&gt;<br>        &lt;h2&gt;Character counter with Alpine&lt;/h2&gt;<br>    &lt;/div&gt;<br><br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><h4>Step 2: Sprinkle some Alpine</h4><pre>&lt;body&gt;<br>    &lt;div class=&quot;header&quot;&gt;<br>        &lt;h2&gt;Character counter with Alpine&lt;/h2&gt;<br>    &lt;/div&gt;<br>    &lt;div x-data=&quot;{<br>        content: &#39;&#39;,<br>        limit: 180<br>    }&quot;&gt;<br>        &lt;textarea&gt;&lt;/textarea&gt;<br>        &lt;p&gt;&lt;/p&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;</pre><p>Let’s pass an object in x-data for the <strong>div</strong>. Let’s say we have some content (a string), which is empty right now and we have a limit equal to 180.</p><p>Also, there is a textarea and below that, we have a paragraph that will finally display the character count.</p><p><strong>Note:</strong> I have actually added some styling beforehand, but you don’t need to worry about it.</p><blockquote><em>Complete code is at the end of this tutorial!</em></blockquote><h4>Step 3: Logic</h4><p>The remaining() function below should basically return the difference between the content&#39;s length and the limit.</p><pre>&lt;div x-data=&quot;{<br>    content: &#39;&#39;,<br>    limit: 180,<br>    remaining() {<br>        return this.limit - this.content.length<br>    }<br>}&quot;&gt;<br>    &lt;textarea x-model=&quot;content&quot;&gt;&lt;/textarea&gt;<br>    &lt;p&gt;<br>        You have &lt;span x-html=&quot;remaining()&quot;&gt;&lt;/span&gt; character left!<br>    &lt;/p&gt;<br>&lt;/div&gt;</pre><ul><li>A <strong>span</strong>, because we actually want to calculate the difference between the <strong>limit</strong> and the <strong>content</strong>.</li><li>The easiest way is to create a remaining() function, which will basically return the difference between the limit and the length of the content.</li><li>Let’s use and call this inside the span. This would update the inner HTML content of the span with the return of the remaining() function.</li><li>At the moment, Alpine doesn’t know what we have inside the textarea as it doesn&#39;t know what the content is. How can I bind this <strong>content</strong> variable with my text area? We can use <strong>x-model </strong>for that.</li></ul><p><strong>VOILA!</strong></p><p>We have a pretty good working application, which basically tells us how many characters you have entered or how many characters you can enter at the moment.</p><h3>Complete Code</h3><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br><br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Document&lt;/title&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js&quot; defer&gt;&lt;/script&gt;<br>    &lt;style&gt;<br>        textarea {<br>            width: 95%;<br>            height: 150px;<br>            padding: 12px 20px;<br>            box-sizing: border-box;<br>            border: 2px solid #ccc;<br>            border-radius: 4px;<br>            background-color: #f8f8f8;<br>            resize: none;<br>            margin-top: 20px;<br>            margin-left: 2.5%;<br>        }<br><br>        p {<br>            margin-left: 2.5%;<br>        }<br><br>        .header {<br>            padding-top: 10px;<br>            padding-bottom: 10px;<br>            text-align: center;<br>            background: #1abc9c;<br>            color: white;<br>            width: 95%;<br>            margin-left: 2.5%;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>    &lt;div class=&quot;header&quot;&gt;<br>        &lt;h2&gt;Character counter with Alpine&lt;/h2&gt;<br>    &lt;/div&gt;<br>    &lt;div x-data=&quot;{<br>        content: &#39;&#39;,<br>        limit: 180,<br>        remaining() {<br>            return this.limit - this.content.length<br>        }<br>    }&quot;&gt;<br>        &lt;textarea x-model=&quot;content&quot;&gt;&lt;/textarea&gt;<br>    &lt;p&gt;<br>        You have &lt;span x-html=&quot;remaining()&quot;&gt;&lt;/span&gt; character left!<br>    &lt;/p&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><p>I hope this article helped you to understand the basics of Alpine.js</p><p>Thanks for reading. If you have any questions, feel free to leave a response.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhTt-1wK6BQ0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhTt-1wK6BQ0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhTt-1wK6BQ0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/af6ef211a4e07d7feda21013b0660b34/href">https://medium.com/media/af6ef211a4e07d7feda21013b0660b34/href</a></iframe><h3>Resources</h3><ol><li><a href="https://github.com/alpinejs/alpine">https://github.com/alpinejs/alpine</a></li><li><a href="https://www.smashingmagazine.com/2020/03/introduction-alpinejs-javascript-framework/">https://www.smashingmagazine.com/2020/03/introduction-alpinejs-javascript-framework/</a></li><li><a href="https://www.alpinetoolbox.com/">https://www.alpinetoolbox.com/</a></li></ol><p><em>Originally published at </em><a href="https://www.theimmigrantprogrammers.com/p/alpinejs-101-understanding-the-basics"><em>https://www.theimmigrantprogrammers.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76890650046" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/alpine-js-101-understanding-the-basics-in-3-minutes-76890650046">Alpine.js 101: Understanding the basics</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The easiest way to create your first React app]]></title>
            <link>https://javascript.plainenglish.io/the-easiest-way-to-create-your-first-react-app-5b2acb6dd518?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b2acb6dd518</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 08:04:01 GMT</pubDate>
            <atom:updated>2021-02-19T19:23:00.456Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step by step guide on creating your first ever React website | create-react-app</h3><p>Let’s create React apps with absolutely no build configuration. It takes less than 30 seconds and only one command that you need to run on your terminal to get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8McxlbyUIPLRS_3E" /><figcaption>Photo by <a href="https://unsplash.com/@giabyte?utm_source=medium&amp;utm_medium=referral">Gia Oris</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>However, before getting into it, let me address the audience who’s new to create-react -app.</p><h3>What is create-react-app?</h3><ol><li>It’s basically a tool built by developers at Facebook.</li><li>It gives us a massive head start when we start building React apps.</li><li>It saves us from time-consuming setup and configuration.</li><li>You simply have to run one command and Create React App sets up the tools you need to start your React project.</li></ol><h3>Philosophy Behind It</h3><h4>1) One Dependency</h4><p>Without it, there would be tens of dependencies that you have to handle/install yourself and you also have to manage all of them whenever a new react version comes out. So let’s say right now you are on react version 10 and you have to upgrade to 12. You have to go through each and every dependency to see if they are compatible with the newest React version and then you have to upgrade them. Not only that, you have to look out for any breaking changes that come with each dependency’s major release version.</p><p>That’s a lot of work!</p><blockquote><em>The basic philosophy behind this initiative (create-react-app) by Facebook is that there’s only one dependency.</em></blockquote><h4>2) No Configuration Required</h4><p>It uses Webpack, Babel, ESlint, and many other amazing projects but it provides you with a curated experience on top of them also there is no configuration required.</p><blockquote><em>A reasonably good amount of configuration for both development and production builds is already handled for you so you can focus on writing your code.</em></blockquote><h4>3) No Lock-In</h4><p>Also, there’s no lock-in. If you are an experienced programmer and you want to custom setup. For that, you can anytime run the <strong>eject</strong> command. With a single command, all the configuration and build dependencies will be moved directly into your project so you can pick up right where you left off.</p><h3>Creating our first react app</h3><p>Enough already! Let’s get started with the officially supported way to create single page react applications with only one command.</p><h4>That command is:</h4><pre>npx create-react-app PROJECT_NAME</pre><p>As a side note <strong>npx</strong> comes with <strong>Npm 5.2</strong> or above. So if you have an older version of Npm, I would highly recommend you to go through the <a href="https://reactjs.org/docs/create-a-new-react-app.html">docs</a> and see the instructions for older versions.</p><p>That’s it, this process takes about 30 or 35 seconds. Finally, we have our first ever react application ready to be served and ready to be tested!</p><p>Command to run the application:</p><pre>yarn start (or npm start)</pre><p>If you go to the localhost:3000, our react app is here, up and running and you have officially created your first ever react application =&gt;</p><h3>A glance at the folder structure</h3><p>Let’s glance through the folder structure. It’s a pretty lean folder structure with only a few files (the files that we need).</p><p>The create-react-app library has taken care of a lot of things. For example, if you see the <strong>package.json file</strong>, this file is pretty lean. It essentially has only about seven dependencies and if you actually see a real application created without the create-react-app it has a pretty bulky package.json file and it can be intimidating for new developers.</p><p>Pretty simple, right?</p><h3>Using templates (typescript)</h3><p>You can optionally add a template like this:</p><pre>npx create-react-app PROJECT_NAME --template TEMPLATE_NAME</pre><p>Let’s say I want to start a react application but this time I want it to be a TypeScript application. Well, here you go:</p><pre>npx create-react-app PROJECT_NAME --template typescript</pre><p>A very similar experience as before but this time the template is TypeScript and all the files would be in a TypeScript should format.</p><p>There are many templates that you can choose from. Check out this <a href="https://create-react-app.dev/docs/getting-started/#selecting-a-template">link</a> to learn more.</p><h3>Ejecting your application</h3><p>The final feature of this library is <strong>ejecting</strong> your application.</p><pre>npm run eject</pre><p>This is a one-way operation. Beware, you cannot go back!</p><p>So before running you really need to understand what it actually means. If you aren’t satisfied with the build tool or the configuration choices made by create-react-app library, you can always eject at any time using this command.</p><p>It will remove the single build dependency from your project. Basically, it will bring out all the dependencies directly in your package.json file. Hence, you can now handle dependencies on your own.</p><p>However, you don’t have to ever use the eject. The curated feature that the create react app provides us is mostly suitable for small and middle deployments and you should never feel obligated to use this feature.</p><p>However, if you have a large and complex application and you and you really know what you are doing only then you should be messing with this.</p><p>I hope this article helped you to understand the latest NodeJS release.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FbFxBjSQCOpE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbFxBjSQCOpE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FbFxBjSQCOpE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a731223e069ac8ec3770218a296a232/href">https://medium.com/media/1a731223e069ac8ec3770218a296a232/href</a></iframe><p>Thanks for reading. If you have any questions, feel free to leave a response.</p><h3>Resources</h3><ol><li><a href="https://create-react-app.dev/docs/getting-started">https://create-react-app.dev/docs/getting-started</a></li><li><a href="https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md">https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md</a></li></ol><p><em>Originally published at </em><a href="https://www.theimmigrantprogrammers.com/p/the-easiest-way-to-create-your-first?r=ch20b&amp;utm_campaign=post&amp;utm_medium=web&amp;utm_source=copy"><em>https://www.theimmigrantprogrammers.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b2acb6dd518" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-easiest-way-to-create-your-first-react-app-5b2acb6dd518">The easiest way to create your first React app</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Features And Breaking Changes In TypeScript 4]]></title>
            <link>https://javascript.plainenglish.io/features-and-breaking-changes-in-typescript-4-111e6551cd7?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/111e6551cd7</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Thu, 26 Nov 2020 17:51:44 GMT</pubDate>
            <atom:updated>2020-11-26T17:51:44.005Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nkpNOMI76YvPdjgk" /><figcaption>Photo by <a href="https://unsplash.com/@ikukevk?utm_source=medium&amp;utm_medium=referral">Kevin Ku</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A new version of TypeScript released on August 26, typescript 4. In this article, we will discuss all the new features, improvements, and breaking changes that were released with the latest Typescript version.</p><h3>Who should read this article?</h3><ol><li><strong>Anyone who has a basic knowledge of JavaScript or TypeScript</strong></li><li><strong>Frontend developers (Angular/React):</strong> Typescript is the foundation of Angular. We are already at angular version 11 and 12 is right around the corner and as angular/front-end developers it’s our duty to keep ourselves up to date with typescript so that we can write code that is not really outdated and we can leverage all the new features that Microsoft and the typescript team are working on every day to make our lives better.</li><li><strong>Programmers who to be up to date</strong></li></ol><h3><a href="https://medium.com/javascript-in-plain-english/typescript-101-understanding-the-basics-in-3-minutes-e2113a9c4c5f">What is TypeScript?</a></h3><ol><li>It’s a language that builds on top of JavaScript.</li><li>It basically adds syntax for our static types.</li><li>The idea is to use typescript to basically type check your code and tell you the mistakes before you run your code.</li></ol><p>For example, in a javascript environment you might write:</p><pre>let a = &quot;cat&quot;;</pre><p>In the very next line, you can write:</p><pre>a = 24; // and this is a problem!</pre><p>and no one is going to stop you, not your compiler, not your IDE and neither will you know it yourself unless the code breaks because you were expecting a string and you got an integer and you will only know it post-production.</p><blockquote><em>So basically the goal of typescript is to avoid those errors avoid those obvious mistakes make our code cleaner and more readable.</em></blockquote><h3>Summary of what’s new in TypeScript 4.0</h3><ol><li>Labeled Tuple Elements</li><li>Class Property Inference from Constructors</li><li>Short-Circuiting Assignment Operators</li><li>Better catch clause bindings</li><li>VS Code improvements</li></ol><h3>Labeled Tuple Elements</h3><p>The first change I’m most excited about is label tuple elements. Those who are not new to programming know that we can pass tuples as a variable number of arguments to any function so that the function can be really dynamic.</p><pre>// Javascript =&gt;</pre><pre>function addressJs(...args) {<br>    // ...<br>}</pre><pre>addressJs(2505, &#39;Sherbrooke East&#39;);</pre><pre>addressJs(&#39;Sherbrooke East&#39;, 2505, 10); // oops!</pre><p>Although TypeScript supports it from the very beginning:</p><pre>// TypeScript &lt; 4.0 =&gt;  </pre><pre>function addressTs(...args: [number, string]): void {<br>    // ...<br>}</pre><pre>addressTs(2505, &#39;Sherbrooke East&#39;); // works</pre><pre>addressTs(2505, &#39;Sherbrooke East&#39;, true); // error<br>addressTs(2505); // error</pre><p>In this function addressTs we had two arguments, the first a number and the second one a string.</p><p>However, it appears no different than this function below:</p><pre>function addressTs2(arg0: number, arg1: string): void {<br>    // ...<br>}</pre><pre>addressTs2(2505, &#39;Sherbrooke East&#39;); // works</pre><p>It basically means that argument zero is a number and argument one is a string.</p><blockquote><em>This is already much better than javascript because in javascript you won’t know if we have to pass a string first and a number second.</em></blockquote><p><strong>Problem: </strong>In this example, it is not obvious to a programmer if he/she should pass an apartmentNumber as a first argument and a city as a second argument or a streetNumber or a streetName!</p><p>There can be various scenarios and there can be a lot of confusion around it.</p><h4>What changed with TypeScript 4?</h4><p>Now what is better is that we can name the tuples. For example, we had to define the range we can actually say that the first variable is labeled as start and the second one is end this greatly increases the readability of the code.</p><pre>// In TypeScript 4.0, tuples types can now provide labels =&gt;</pre><pre>type StreetAddress = [streetNumber: number,streetName: string] <br>| [streetNumber: number, streetName: string, city: string];</pre><pre>function addressWithLabels(...address: StreetAddress): void {<br>    //...<br>}</pre><pre>addressWithLabels(2525, &#39;Sherbrooke East&#39;); //works<br>addressWithLabels(2525, &#39;Sherbrooke East&#39;, &#39;Montreal&#39;); //works</pre><p>Now we can define or label our arguments. We can say that the first one should be a streetNumber and the second one should be a streetName.</p><p>This method accepts a street address. Now street address can either have a street number and street name or it can have a street number, street name, and a city. Hence, it’s pretty clear now.</p><p>This will help when we have a large codebase! In big companies we have thousands of lines of code and if these things can make the life of programmers easy and better then why not implement them.</p><blockquote><em>Also, we don’t have to rely on documentation or comments. This kind of code is pretty readable and it would be pretty obvious what kind of arguments we need to pass.</em></blockquote><p>If you really want to leverage the variable number of arguments:</p><pre>type StreetAddressComplete = [<br>    streetNumber: number,<br>    streetName?: string,<br>    ...rest: any[]<br>];</pre><p>In this example, we can say that the first one has to be a <strong>streetNumber</strong> which will be a <strong>number</strong> type second one has to be a <strong>string</strong> and the third one well they can have as many arguments as we want to have of any type. So we can still leverage the variable number of arguments.</p><h3>Class Property Inference from Constructors</h3><p>Now typescript can use the control flow to analyze what the type of these variables are in a situation like this where you define a class <strong>Square</strong> with <strong>area</strong> and <strong>sideLength</strong> but you didn’t give types:</p><pre>class Square {<br>    // Previously: implicit any!<br>    // Now: inferred to `number`!<br>    area;<br>    sideLength;</pre><pre>    constructor(sideLength: number) {<br>        this.sideLength = sideLength;<br>        this.area = sideLength ** 2;<br>    }<br>}</pre><p>It analyzes that in the constructor you passed a number and then you assigned the number and did some manipulation on it and assigned it to the area as well. But typescript is smart enough to know that it’s still a number and it will assume that your variables are numbers.</p><p>However, it has a limitation, for example:</p><pre>class Square {<br>    sideLength;</pre><pre>    constructor(sideLength: number) {<br>        if (Math.random()) {<br>            this.sideLength = sideLength;<br>        }<br>    }</pre><pre>    get area() {<br>        return this.sideLength ** 2;<br>        //     ~~~~~~~~~~~~~~~<br>        // error! Object is possibly &#39;undefined&#39;.<br>    }<br>}</pre><p>In this case, it’s assigned inside an <strong>if</strong> condition. So in this case typescript’s compiler won’t know for sure that the type of this variable is now a number or not because there is a potential for it to be undefined.</p><h3>Short-Circuiting Assignment Operators</h3><p>With TypeScript 4 they announced that now we have three new assignment operators:</p><ol><li>&amp;&amp;=</li><li>||=</li><li>??=</li></ol><p>So basically we could replace these assignments</p><pre>a = a &amp;&amp; b; <br>a = a || b; <br>a = a ?? b;</pre><p>with the new ones.</p><blockquote><em>Every programmer likes shorter code.</em></blockquote><h3>Better catch clause bindings</h3><pre>try {<br>    // ...<br>}<br>catch (x) {<br>    // x has type &#39;any&#39; - have fun!<br>    console.log(x.toUpperCase());<br>    x++;<br>}</pre><p>It basically means that earlier if we had a try and a catch block we don’t know what type x is it can be of type any we can do an operation that was supposed to be for integers only and it won&#39;t throw an error before the code actually executes.</p><p>Now we have a type unknown that we can define that we can assign to the exception:</p><pre>try {<br>    // ...<br>}<br>catch (e: unknown) {<br>    console.log(e.toUpperCase()); // compile error<br>    if (typeof e === &quot;string&quot;) {<br>       console.log(x.toUpperCase()); <br>    }<br>}</pre><p>Now if we try to say e.toUpperCase() the compiler will throw an error because it doesn&#39;t think that type unknown has this method. So instead we have to narrow it down. If the type of exception (e) is a string only then we can call it.</p><blockquote><em>This can be pretty handy because you don’t want errors or exceptions in your catch code!</em></blockquote><h3>Breaking changes</h3><p>In the end, I just want to mention that there’s no major breaking change with this release so you can simply update the typescript version in your codebases and you’re good to go!</p><p>I hope this article helped you to understand the latest TypeScript release.</p><p>Thanks for reading. If you have any questions, feel free to leave a response.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FM9ofYHuWfo8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DM9ofYHuWfo8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FM9ofYHuWfo8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/43fb44804690ab0efcb7d781f8718d41/href">https://medium.com/media/43fb44804690ab0efcb7d781f8718d41/href</a></iframe><h3>Resources</h3><ol><li><a href="https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/">https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=111e6551cd7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/features-and-breaking-changes-in-typescript-4-111e6551cd7">Features And Breaking Changes In TypeScript 4</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything about the latest Node.js release | Node.js 15]]></title>
            <link>https://javascript.plainenglish.io/everything-about-the-latest-node-js-release-node-js-15-ad934e0dd9f4?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad934e0dd9f4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Mon, 23 Nov 2020 12:32:56 GMT</pubDate>
            <atom:updated>2020-11-23T23:57:42.510Z</atom:updated>
            <content:encoded><![CDATA[<h4>Node.js v15 is here!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LWaf2iypTmXeYogz.png" /></figure><p>But wait, I just upgraded my project to Node 12 and you’re telling me that a new version is already released! I haven’t even upgraded my project to node 14! Should I directly go to note 15 now? But wait what are the breaking changes? Also, what are the new features? Is there any benefit of even upgrading? Should I even think of it?</p><p>If you ever had any of these questions don’t worry about it as I’m here to tell you everything you need to know about node.js latest version if you need to upgrade to it, what are the breaking changes and what are the new features.</p><h3>Summary of the major changes:</h3><ol><li><strong>Abort controller: </strong>It’s basically an experimental implementation but it’s very useful. It basically helps us to reject or abort any kind of promise-based API</li><li><strong>Npm 7:</strong> There’s a new npm version major release that came out and it has some changes in the package-lock.json format and also it introduced npm workspaces.</li><li><strong>V8 8.6:</strong> v8 javascript engine has been upgraded to 8.6. For those who don’t know 8.4 was already released in note 14.<br>- Promise.any()<br>- AggregateError<br>- String.prototype.replaceAll()<br>- &amp;&amp;=, ||= and ??=</li><li><strong>Breaking Changes</strong></li></ol><blockquote>Let me first address the elephant in the room: Do you need to upgrade your project to node 15? The simple answer is NO! Don’t be surprised as it’s an odd-numbered release line and node js 15 will not be promoted to LTS (Long Term Support).</blockquote><p>Whenever Node.js comes out with an odd number release it is not going to be promoted to LTS and whenever it comes out with an even number release that is what you should really upgrade your applications to because it will go to long-term support and it will stay for a long time.</p><h3>AbortController</h3><blockquote><em>It’s basically a new experimental implementation that allows us to cancel any kind of promise-based API.</em></blockquote><p>This is very cool because before this we could only unsubscribe to the API calls we have already made but we didn’t really abort them they were still executed we just didn’t listen to the response. With AbortController we can actually abort any kind of API request: it can be a response body type or it can even be a stream (like downloading a video).</p><pre>var controller = new AbortController();<br>var signal = controller.signal;<br><br>var downloadBtn = document.querySelector(&#39;.download&#39;);<br>var abortBtn = document.querySelector(&#39;.abort&#39;);<br><br>downloadBtn.addEventListener(&#39;click&#39;, fetchVideo);<br><br>abortBtn.addEventListener(&#39;click&#39;, function() {<br>  controller.abort();<br>  console.log(&#39;Download aborted&#39;);<br>});<br><br>function fetchVideo() {<br>  ...<br>  fetch(url, {signal}).then(function(response) {<br>    ...<br>  }).catch(function(e) {<br>    reports.textContent = &#39;Download error: &#39; + e.message;<br>  })<br>}</pre><p>Let’s go through the basic code real quick in order to actually understand what’s happening behind the scenes.</p><p>So first we need to create a controller using the abort controller constructor and then grab a reference to its associated signal using the controller.signal property.</p><p>Now we have two buttons in the HTML which are basically a download button and an abort button. On the download button, we add an event that basically listens to a click event and whenever that happens it starts fetching the video. On the other hand, the abort button also listens to a click event but it actually aborts the controller, and then it logs “Download aborted”.</p><blockquote><em>I’m sure you understand at least a little bit of it as I said it’s still experimental so I don’t recommend you start using this in your production applications.</em></blockquote><p>Read more about AbortController <a href="https://developer.mozilla.org/en-US/docs/Web/API/AbortController">here</a>.</p><p><a href="https://mdn.github.io/dom-examples/abort-api/">AbortController Live Example</a></p><h3>NPM 7</h3><p>We won’t dive deep into this change because this actually needs an article of its own. I would just give you a brief overview of what changed and what are the new features!</p><p>For those who don’t know what’s NPM: it’s used by millions of developers, it has millions of libraries and it has about 75 billion downloads a month so you really need to check it out.</p><h4>New features:</h4><ol><li><strong>Workspace: </strong>A<strong> </strong>workspace that now helps us to manage multiple projects within a single top-level package.</li><li><strong>Automatically install peer dependencies:</strong> Now it automatically installs the peer dependencies. From NPM 7 developers will need to manage their own peer dependencies. This might be a breaking change for a few applications. Now if you’re thinking about what peer dependency is, I highly recommend you to go through the docs but I’ll give you a brief overview: let’s say you have a library or you have an NPM package that is published and it has some peer dependencies. Now before this release, your package did not have to install any of the peer dependency. Any application or any service that uses your package needs to install it.</li></ol><h3>Promise.any() and AggregateError</h3><p>Promise.any() basically takes a number of promises and it resolves as soon as one of the promises is completed.</p><blockquote><em>It is the exact opposite of promise.all().</em></blockquote><p>In promised.all() we used to pass a number of promises but it only used to resolve when each and every promise that we have passed is resolved. On the other hand, in this case, we wait for any one of them to resolve so it’s the exact opposite of promised.all()</p><p>Now you must be thinking about what happens if all of the promises we have passed to promise.any() fail! Well in that case it will return an <strong>AggregateError</strong> which is a new subclass of error which is also released with v8 8.6.</p><pre>const promise1 = Promise.reject(0);<br>const promise2 = new Promise((resolve) =&gt; setTimeout(resolve, 100, &#39;quick&#39;));<br>const promise3 = new Promise((resolve) =&gt; setTimeout(resolve, 500, &#39;slow&#39;));</pre><pre>const promises = [promise1, promise2, promise3];</pre><pre>Promise.any(promises).then((value) =&gt; console.log(value));</pre><pre>// expected output: &quot;quick&quot;</pre><p>In the example over here, we have three promises. The first one is rejected as you can see. The second one resolves in 100 milliseconds and the third one resolves in 500 milliseconds.</p><p>Now we group them in an array and we pass and promise.any() and it will resolve as soon as the first promise is resolved and will return us the value of the promise that has resolved the first so when we run it you can see that it prints “quick”.</p><p>So basically it didn’t wait for the one with 500 milliseconds delay and it didn’t reject because one of the promises was rejected. It basically returned us the value of the first promise that was completed successfully.</p><h3>String.prototype.replaceAll()</h3><p>The <strong>replaceAll()</strong> method returns a new string with all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp. The original string is left unchanged.</p><pre>const p = &#39;The quick brown fox jumps over the lazy dog.&#39;;</pre><pre>console.log(p.replaceAll(&#39;dog&#39;, &#39;monkey&#39;));</pre><pre>// expected output: &quot;The quick brown fox jumps over the lazy monkey.&quot;</pre><p>As you can see in this example we have a string over here and we want to replace all the “dog” with “monkey”.</p><p>Finally, Node.js has been with us for a little over 10 years now and they have done nothing but improved themselves and they plan to do the same in the next 10 years and they have already laid out a roadmap for the next 10 years. They have taken it to a whole another level this time they started taking surveys of the contributors and they started taking into consideration the changes for the features that are the most requested.</p><p>I hope this article helped you to understand the latest Node.js release.</p><p>Thanks for reading. If you have any questions, feel free to leave a response.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1c6cDNizrys%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1c6cDNizrys&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1c6cDNizrys%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1319dad432e1ea7de8e28089357d76e/href">https://medium.com/media/f1319dad432e1ea7de8e28089357d76e/href</a></iframe><h3>Resources</h3><ol><li><a href="https://nodejs.org/en/blog/release/v15.0.0">https://nodejs.org/en/blog/release/v15.0.0</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/AbortController">https://developer.mozilla.org/en-US/docs/Web/API/AbortController</a></li><li><a href="https://github.blog/2020-10-13-presenting-v7-0-0-of-the-npm-cli/">https://github.blog/2020-10-13-presenting-v7-0-0-of-the-npm-cli/</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad934e0dd9f4" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/everything-about-the-latest-node-js-release-node-js-15-ad934e0dd9f4">Everything about the latest Node.js release | Node.js 15</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript 101: Understanding the basics in 3 minutes!]]></title>
            <link>https://javascript.plainenglish.io/typescript-101-understanding-the-basics-in-3-minutes-e2113a9c4c5f?source=rss-710bfdad0433------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2113a9c4c5f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Pranav Bhatia]]></dc:creator>
            <pubDate>Tue, 24 Mar 2020 20:41:19 GMT</pubDate>
            <atom:updated>2023-03-13T05:29:11.657Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn the basics like types, classes, interface generics and more! Get your hands dirty with TS in <em>[const </em><strong>minutes</strong><em>: number = 3]</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wzZsz_2GtmHoWMUO" /><figcaption>Photo by <a href="https://unsplash.com/@grohsfabian?utm_source=medium&amp;utm_medium=referral">Fabian Grohs</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So, there has been a lot of buzz surrounding typescript for quite a while now. Especially since Angular started using TypeScript as its primary language. Now, you might think: Angular was developed by <strong>Google</strong>, a company that has pretty smart programmers (top 4%, some might say). If they choose TS over JS, there must be a good reason!</p><p>Well, you are right! and here are a few reasons to learn TS, ASAP!</p><ol><li>TypeScript is the future of JavaScript (some might disagree!)</li><li>Typescript code is like a well-documented code, hence, it’s easier to understand.</li><li>It has classes, interfaces, generics, etc. like any other object-oriented programming language.</li></ol><p>Let’s have a look at a basic typescript function and then you can be the judge:</p><pre>function calculateGrade(course1: number, course2: number) : string {<br>    return (course1 + course2) &gt; 70 ? &#39;A&#39; : &#39;B&#39;;<br>}</pre><p>What did we learn? The function <strong>calculateGrade </strong><em>accepts</em> <em>two arguments of the type </em><strong><em>number</em></strong><em> and returns a grade of type </em><strong><em>string</em></strong><em> in the end.</em></p><p>This might look obvious, but if it was JavaScript, there is almost no easy way to know “what kind of variables you should use when calling this function?” or “what will it return, a number or a string?” And thus, leading to potential bugs in the end.</p><blockquote>Now, what if after reading the function above, you still make a mistake and try passing a string as an argument to the above function. <br>Well, in the case of JS, you will only know it when it&#39;s already too late.<br>However, our friendly TS will let us know right away. <br>If you don’t believe me, see below:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M4TTs7I3TWXkMFi4q1LeRw.png" /><figcaption>Hence, fewer bugs!</figcaption></figure><p>Okay, alright, enough talking. Let’s move on to learning some basics of TypeScript that will help you to get started.</p><h4>Types</h4><p>As the name suggests, TypeScript has types! We have already seen the type <em>number</em> and <em>string</em> above. What else…</p><h4>Classes</h4><p>Have a look at the code below, don’t you think this kind of code is easier to comprehend and less error-prone.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5424e21caadb71383e57fa0d245d67a/href">https://medium.com/media/d5424e21caadb71383e57fa0d245d67a/href</a></iframe><p><em>Code Explanation: Think of the “Employee” class as a blueprint. This piece of code, although pretty basic, explains some of the very important concepts of typescript. Also, note that the </em><strong><em>salary</em></strong><em> variable is </em><strong><em>private. </em></strong><em>That means we cannot directly access this variable. See the snapshot below:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35oDB2VpxfNms1xfhoTsrg.png" /><figcaption>Typescript compiler lets you know these kinds of errors beforehand. Remember OOP concepts?</figcaption></figure><p>For more information on classes (typescriptlang.org): <a href="https://www.typescriptlang.org/docs/handbook/classes.html">classes</a>.</p><h4>Interfaces: <em>create your own custom-types</em></h4><p>We already know that we can use types like string, number, boolean, etc. What if we want to create our own custom types for enforcing checks in our code. Luckily we can use interfaces for that!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03373e441611a51ffa09e63fd76befa4/href">https://medium.com/media/03373e441611a51ffa09e63fd76befa4/href</a></iframe><p>Interfaces can be really useful and are heavily used in frameworks like Angular/React. We can also use “model” classes or “types” depending on the use-case.</p><p>For more information on interfaces (typescriptlang.org): <a href="https://www.typescriptlang.org/docs/handbook/interfaces.html">interfaces</a>.</p><h4>Generics</h4><p>Generics is a very simple, yet powerful feature of typescript. Using generics is widely appreciated while working on services/APIs that other developers might use, especially, open-source ones. It helps to know what kind of data to expect and hence, resulting in reduced errors and confusion.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef2090fdc68dd88d475fc3e83905b957/href">https://medium.com/media/ef2090fdc68dd88d475fc3e83905b957/href</a></iframe><p>For more information on generics (typescriptlang.org): g<a href="https://www.typescriptlang.org/docs/handbook/generics.html">enerics</a>.</p><p>I hope to those who are new to typescript, this articles helped you to understand the benefits of using types in your JS code.</p><h4>Resources</h4><p>You can find the code in this article here: <a href="https://gist.github.com/PranavBhatia">Link to the Github gists</a>.</p><p>Other resources: <a href="https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html">Official typescript handbook</a>.</p><p>Typescript playgrounds used:<br><a href="https://typescript-play.js.org/">https://typescript-play.js.org/</a><br><a href="https://www.typescriptlang.org/play/">https://www.typescriptlang.org/play/</a></p><p>Thanks for reading. If you have any questions, feel free to leave a response.</p><p>To view the original article, please <a href="https://immigrantprogrammers.blogspot.com/2020/09/typescript-101-understanding-basics-in.html">click here.</a></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><h4>Further Reading</h4><p><a href="https://javascript.plainenglish.io/typescript-made-easy-a-guide-to-your-first-type-safe-app-with-next-js-wundergraph-and-prisma-e197a59e2b30">TypeScript Made Easy: A Guide To Your First Type-Safe App with Next.js, WunderGraph, and Prisma</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2113a9c4c5f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/typescript-101-understanding-the-basics-in-3-minutes-e2113a9c4c5f">TypeScript 101: Understanding the basics in 3 minutes!</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>