<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Kaushal Joshi - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Kaushal Joshi - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 21 May 2026 16:10:35 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/kaushal-joshi/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Add Aliases to Terminal Commands in Linux and Mac ]]>
                </title>
                <description>
                    <![CDATA[ In this article, we'll explore a simple trick that can save you hours of typing repetitive commands in the terminal. As developers, we spend a substantial amount of time executing commands on the terminal. Whether it's navigating through directories,... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-aliases-to-terminal-commands/</link>
                <guid isPermaLink="false">66bd9096dc6141cf21aaadb6</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ mac ]]>
                    </category>
                
                    <category>
                        <![CDATA[ terminal ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kaushal Joshi ]]>
                </dc:creator>
                <pubDate>Mon, 15 Apr 2024 15:37:42 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/terminal-alias.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article, we'll explore a simple trick that can save you hours of typing repetitive commands in the terminal.</p>
<p>As developers, we spend a substantial amount of time executing commands on the terminal. Whether it's navigating through directories, running scripts, changing Node.js versions, or version control commands, manually typing every command is a time consuming task. </p>
<p>For those who struggle to remember commands or their associated flags, this can become even more tedious.</p>
<p>Worry not! There's a simple yet powerful solution to this problem. It's called terminal aliases.</p>
<h2 id="heading-the-alias-command">The <code>alias</code> Command</h2>
<p>The <code>alias</code> command allows you to create shortcuts for existing commands, making them easier to remember and quicker to execute. When you define an alias, you are creating a new label for an existing command.</p>
<h3 id="heading-syntax-of-alias-command">Syntax of <code>alias</code> Command</h3>
<p>The syntax is straightforward: you can assign a command to a label like you'd assign a value to a variable in most programming languages.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">alias</span> alias_name=<span class="hljs-string">'long command'</span>
</code></pre>
<p>Let's dissect this command to understand it better:</p>
<ul>
<li><code>alias</code>: The terminal command that enables defining an alias.</li>
<li><code>alias_name</code>: This is the name or the label you are assigning to the command. Basically, you will type this in the terminal instead of the full command.</li>
<li><code>'long command'</code>: This is the command that you want to add an alias to. Make sure that you are wrapping the command with single quotes (<code>'</code>) as almost all commands contain spaces or special characters. </li>
</ul>
<h2 id="heading-predefined-aliases">Predefined Aliases</h2>
<p>There are some predefined aliases already set within terminals. And there is a high chance that you were using them without even knowing.</p>
<p>Such aliases are defined within the system (<code>/etc/bash.bashrc</code>) or user specific (<code>~/.bsahrc</code>) shell configuration files. </p>
<p>You can find a list of all predefined aliases by executing the <code>alias</code> command without any options or flags.</p>
<pre><code>alias
</code></pre><h2 id="heading-how-to-create-an-alias-that-persists-across-sessions">How to Create an Alias that Persists Across Sessions</h2>
<p>By default, aliases only persist in the current session. That means, if you close the terminal, the alias will be erased and you cannot use it afterwards.</p>
<p>To tackle this, you must define the alias in the shell's configuration file. Shell is an interpreter that resides inside a terminal and establishes an interface between you and the operating system. Hence, accessing the correct shell as well as modifying the correct configuration file is very important.</p>
<p>Here are the configuration files for the three most commonly used shell applications:</p>
<ol>
<li><strong>Bash</strong>: <code>~/.bashrc</code></li>
<li><strong>Zsh</strong>: <code>~/.zshrc</code></li>
<li><strong>Fish</strong>: <code>~/.config/fish/config.fish</code></li>
</ol>
<p>Let's try adding a new alias to Bash.</p>
<pre><code>echo <span class="hljs-string">"alias nrd='npm run dev'"</span> &gt;&gt; ~/.bashrc
</code></pre><p>Let's dissect this command:</p>
<ul>
<li><code>echo</code>: A terminal command that lets you write content within the terminal command.</li>
<li><code>"alias ..."</code>: This is the content we talked about in the previous point. It's an alias command that adds <code>nrd</code> as an alias for the <code>npm run dev</code> command. </li>
<li><code>&gt;&gt;</code>: Tells the terminal to append the content on the left (alias command) to the file on the right. In our case, we are storing it in the bash configuration file.</li>
<li><code>~/.bashrc</code>: This is the file to which the content from the echo command will be added.</li>
</ul>
<p>Don't forget to replace <code>~/.bashrc</code> with your shell's configuration file.</p>
<h2 id="heading-how-to-create-a-dynamic-alias">How to Create a Dynamic Alias</h2>
<p>Oftentimes, you need to use repetitive commands but with some little changes based on what you want. The best example of this is Git commands. In this case, you can add a substitute to your command which would be replaced by the dynamic option/parameter while executing it in the terminal.</p>
<pre><code>alias gpll=<span class="hljs-string">'git pull --rebase origin ${branch}'</span>
</code></pre><p>While executing the command, you need to replace <code>${branch}</code> with the branch you want to pull changes from. This is how you would do it to pull changes from the <code>main</code> branch:</p>
<pre><code>gpll main
</code></pre><p>You can also add multiple substitutes to your alias. Just make sure you are writing the alias with the correct order of actual values:</p>
<pre><code>alias gpll=<span class="hljs-string">'git pull --rebase ${remote} ${branch}</span>
</code></pre><p>While executing the command, you need to replace <code>${remote}</code> and <code>${branch}</code> with appropriate values, like the following:</p>
<pre><code>gpll origin main
</code></pre><h2 id="heading-how-to-create-an-alias-for-multiple-commands">How to Create an Alias for Multiple Commands</h2>
<p>There are cases where you need to use multiple commands sequentially. You can create an alias for that as well. Separate each command by <code>&amp;&amp;</code> which executes the command on the right after the command on the left is executed.</p>
<pre><code>gpsh=<span class="hljs-string">'git pull --rebase &amp;&amp; git push'</span>
</code></pre><h2 id="heading-how-to-delete-an-alias">How to Delete an Alias</h2>
<p>If you want to delete an alias from the current session, you can use the <code>unalias</code> command. This command takes only one argument — the alias name.</p>
<pre><code>unalias my-alias-name
</code></pre><p>However, if you want to delete an alias saved in the configuration file, you need to delete it from the file itself. You can use a simple text editor like <a target="_blank" href="https://help.ubuntu.com/community/Nano">Nano</a> to do this.</p>
<pre><code>nano ~/.bashrc
</code></pre><p>Scroll down to the bottom to find all of your aliases and delete the ones you don't want anymore.</p>
<p>When you're done, you can exit the editor after saving. This is the place where I can introduce a meme about not being able to exit terminal-based text editors. But with Nano, it's very simple:</p>
<ol>
<li>Press <code>ctrl</code>+<code>x</code> if you are on Linux and <code>^</code>+<code>x</code> if you are on Mac.</li>
<li>Press <code>Y</code> to confirm changes</li>
<li>Hit Enter or return based on your operating system to save the file.</li>
</ol>
<p>See? Nothing difficult :)</p>
<h2 id="heading-caveats">Caveats</h2>
<p>There are two important things that you must remember while creating an alias.</p>
<h3 id="heading-aliases-are-shell-restricted">Aliases are shell-restricted</h3>
<p>Aliases are specific to the shell you are using. An alias created in one shell won't work in another shell.</p>
<p>You must create a new alias if you want to use it in a different session. There is no workaround to this caveat. One trick you can do is to manually save the alias to the config files of all the shells you use.</p>
<h3 id="heading-aliases-are-session-bound-by-default">Aliases are session bound by default</h3>
<p>Aliases are only available in the current session. If you open a new terminal window or log out, the alias will not be available.</p>
<p>Hence, it's recommended to always save an alias to a configuration file so you use it anytime you want.</p>
<h2 id="heading-tldr">TL;DR</h2>
<ul>
<li><code>alias</code> command adds <em>shortcuts</em> to a command or series of commands. <code>alias shortcut='existing valid command</code>.</li>
<li>Save an alias to the shell's config file so it is persisted across sessions. Every shell has a unique config file. <code>echo "nrd='npm run dev'" &gt;&gt; ~/.bashrc</code>.</li>
<li>Create a dynamic alias by substituting the dynamic value with a placeholder. The placeholder must be wrapped by <code>${}</code>. <code>alias gp='git pull origin ${branch}</code> should be executed as <code>gp main</code> in the terminal.</li>
<li>Add multiple commands to an alias by joining them with <code>&amp;&amp;</code>.</li>
<li>Delete an alias by manually erasing it from the config file. </li>
</ul>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>I hope this blog helps you optimize your time and boosts your developer productivity. If it did, don't forget to share this with your peers so they can improve their efficiency as well.</p>
<p>What other techniques do you use to work efficiently? I would love to know more about it. I am most active on <a target="_blank" href="https://twitter.com/clumsy_coder">Twitter</a> and <a target="_blank" href="https://peerlist.io/kaushal">Peerlist</a>, if you want to say hi!</p>
<p>Until then, happy scripting! 👨‍💻</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Sort an Array of Objects by Property Name in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ In this tutorial, you'll learn about one of the most common operations you'll perform while working with JavaScript: sorting an array of objects by property name. Basic Array Concepts Let's review some basic JavaScript concepts before delving deeper ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-sort-array-of-objects-by-property-name-in-javascript/</link>
                <guid isPermaLink="false">66bd909e621c718d60a31055</guid>
                
                    <category>
                        <![CDATA[ arrays ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kaushal Joshi ]]>
                </dc:creator>
                <pubDate>Mon, 29 Jan 2024 14:45:35 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/12/How-to-sort-an-array-of-objects-by-object-s-property-name-in-JavaScript.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this tutorial, you'll learn about one of the most common operations you'll perform while working with JavaScript: sorting an array of objects by property name.</p>
<h2 id="heading-basic-array-concepts">Basic Array Concepts</h2>
<p>Let's review some basic JavaScript concepts before delving deeper into the subject so that you have the background info you need.</p>
<h3 id="heading-javascript-arrays-and-array-of-objects">JavaScript arrays and array of objects</h3>
<p>Arrays are one of the fundamental building blocks of any programming language. They're the simplest data structure, yet they're so powerful that they're the underlying data structure of many apps we use today.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arr = [<span class="hljs-string">"apple"</span>, <span class="hljs-string">"banana"</span>, <span class="hljs-string">"orange"</span>, <span class="hljs-string">"mango"</span>]
</code></pre>
<p>The most typical use of arrays is to send data from one machine to another. By machine, I mean a client, server, database server, and so on. Such data is often a collection of similar records grouped in an array. Every record is represented by an object, which is an array element.</p>
<p>These arrays are called arrays of objects. Here's an example of an array of objects in JavaScript:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> response = [
    {
        <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
        <span class="hljs-attr">name</span>: <span class="hljs-string">"John"</span>,
        <span class="hljs-attr">age</span>: <span class="hljs-number">41</span>
    },
    {
        <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>,
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Zack"</span>,
        <span class="hljs-attr">age</span>: <span class="hljs-number">35</span>
    },
    {
        <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>, 
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Peter"</span>,
        <span class="hljs-attr">age</span>: <span class="hljs-number">47</span>
    }
]
</code></pre>
<p>As you can see, it's simply an array. And every element in the array is an object. Hence the name, <strong>array of objects</strong>.</p>
<p>You can handle an array of objects like any other array and use built-in array functions. But there are some situations where using built-in functions is not feasible, and you must make certain modifications to achieve the objective.</p>
<h3 id="heading-keys-in-javascript-objects">Keys in JavaScript objects</h3>
<p>Objects in JavaScript are collections of key-value pairs, with each key identifying a specific value. Think of keys as the labels you assign to retrieve information from a dictionary. For instance:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
    <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"John"</span>,
    <span class="hljs-attr">age</span>: <span class="hljs-number">41</span>
};
</code></pre>
<p>In the above example, <code>id</code>, <code>name</code>, and <code>age</code> are keys whereas '1', 'John', and '25' are their corresponding values. When we talk about sorting an array of objects based on a key, we are referring to sorting the array elements based on the values associated with a specific property within each object.</p>
<h3 id="heading-determining-the-data-type-of-a-property">Determining the data type of a property</h3>
<p>Before sorting, it's crucial to understand the data type of the property you intend to use as the sorting key. JavaScript has different sorting rules for numeric and string values. Knowing the data type helps us choose the appropriate sorting method.</p>
<p>If you are unsure of the data type, you can either check the data type with the <code>typeof</code> operator or convert the type into your desired one.</p>
<pre><code class="lang-xml">// Checking if the type is as expected
if(typeof obj.name === "string") {
    // Do something
}

// Converting property's type
const string = String(obj.propertyName)
const number = Number(obj.propertyName)
</code></pre>
<h2 id="heading-how-to-sort-an-array-of-objects-with-a-specific-key-from-the-object">How to Sort an Array of Objects with a Specific Key from the Object</h2>
<p>We need to know two things before sorting an array:</p>
<ol>
<li><p><strong>Data Type:</strong> Understand the data type of the value we want to sort.</p>
</li>
<li><p><strong>Sort Order:</strong> Determine whether we want to sort in ascending or descending order.</p>
</li>
</ol>
<p>We will cover various use cases to get a full picture of these concepts.</p>
<h3 id="heading-how-to-sort-an-array-based-on-numeric-values">How to sort an array based on numeric values</h3>
<p>Let's start by sorting an array based on numeric values, specifically the age property. Our goal is to have the array elements (that is, objects) sorted in ascending order based on the <code>age</code> property. The built-in <code>sort()</code> method will be our tool of choice:</p>
<pre><code class="lang-javascript">response.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a.age - b.age)
</code></pre>
<p>And that's it! Objects in the array are sorted by the <code>age</code> property. You can confirm this by logging the output in the console:</p>
<pre><code class="lang-javascript">[
  { <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Zack'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">35</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'John'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">41</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Peter'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">47</span> }
]
</code></pre>
<p>If you want to sort in descending order, you just need to change the position of the variables inside the function.</p>
<pre><code class="lang-javascript">response.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> b.age - a.age)
</code></pre>
<p>Just like that, the array will be sorted in descending order of <code>age</code>.</p>
<pre><code class="lang-javascript">[
  { <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Peter'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">47</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'John'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">41</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Zack'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">35</span> }
]
</code></pre>
<p>Sorting numbers in an array is easy – so now let's try something a little bit more difficult: sorting based on string values.</p>
<h3 id="heading-how-to-sort-an-array-based-on-string-values">How to sort an array based on string values</h3>
<p>I struggled a lot in my initial days to perform this operation. Eventually, I found the easiest method to do it. Similar to the previous example, here we want to sort objects based on the string values.</p>
<p>We will use a built-in string function <code>localCompare()</code>. It is used for comparing strings based on language-sensitive ordering. Let's write the <code>sort()</code> function with the help of this function:</p>
<pre><code class="lang-javascript">response.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a.name.localeCompare(b.name));
</code></pre>
<pre><code class="lang-javascript">[
  { <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'John'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">41</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Peter'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">47</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Zack'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">35</span> }
]
</code></pre>
<p>As expected, array elements will be sorted based on the <code>name</code> property inside each object element.</p>
<p>Sorting in descending order is a no-brainer as well:</p>
<pre><code class="lang-javascript">response.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> b.name.localeCompare(a.name));
</code></pre>
<p>The output will be like the following:</p>
<pre><code class="lang-javascript">[
  { <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Zack'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">35</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'Peter'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">47</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">'John'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">41</span> }
]
</code></pre>
<h2 id="heading-edge-cases-to-consider">Edge Cases to Consider</h2>
<p>While sorting arrays of objects, it's essential to address potential edge cases.</p>
<h3 id="heading-the-key-must-be-present-in-all-objects">The key must be present in all objects</h3>
<p>Ensure that the key used for sorting exists in all objects. Even if a single object is missing the key, the original array is returned unchanged. Here's how you can handle such a case:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (array.every(<span class="hljs-function"><span class="hljs-params">obj</span> =&gt;</span> <span class="hljs-string">'age'</span> <span class="hljs-keyword">in</span> obj)) {
    array.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a.age - b.age);
} <span class="hljs-keyword">else</span> {
    <span class="hljs-built_in">console</span>.error(<span class="hljs-string">"Some objects lack the 'age' key. Sorting is not feasible."</span>);
}
</code></pre>
<h3 id="heading-null-or-undefined-values-must-not-be-present">Null or undefined values must not be present</h3>
<p>The key you want to use for sorting shouldn't be <code>null</code> or <code>undefined</code>. You can pass an empty string instead of the key if it is a falsy value.</p>
<pre><code class="lang-javascript">array.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> (a.name || <span class="hljs-string">""</span>).localeCompare(b.name || <span class="hljs-string">""</span>));
</code></pre>
<h3 id="heading-all-values-must-be-strings-for-string-comparisons">All values must be strings for string comparisons</h3>
<p>While sorting objects based on a particular key, if the key is supposed to be a string, then make sure that the key has the data type String in all cases. A workaround to avoid potential bugs is to convert the key into a string in the <code>sort()</code> function.</p>
<pre><code class="lang-javascript">array.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> <span class="hljs-built_in">String</span>(a.name).localeCompare(<span class="hljs-built_in">String</span>(b.name)));
</code></pre>
<h3 id="heading-local-sensitivity">Local sensitivity</h3>
<p>When dealing with string properties, consider language and case sensitivity. Provide appropriate locales and options information for <code>localeCompare()</code>.</p>
<pre><code class="lang-javascript">array.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a.title.localeCompare(b.title, <span class="hljs-string">'en'</span>, { <span class="hljs-attr">sensitivity</span>: <span class="hljs-string">'accent'</span> }));
</code></pre>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>Understanding array operations will increase the efficiency of your code and improve the performance of your app. In this article, you learned how to sort arrays of objects based on a key from inside the object.</p>
<p>I hope you found this article helpful. If you do, don't forget to share it with your friends so others can benefit from it. If you know a better method to sort arrays, let me know! I would love to learn.</p>
<p>I am most active on <a target="_blank" href="https://twitter.com/clumsy_coder">Twitter (Now <strong>X</strong>)</a> if you want to say hi!</p>
<h3 id="heading-further-readings">Further readings</h3>
<ul>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">JavaScript sort() function</a></p>
</li>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator">Intl.Collator object</a></p>
</li>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare">JavaScript localeCompare() function</a></p>
</li>
</ul>
<p>Until next time, happy coding :)</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What to Know About GPT-4 for Non-AI Developers ]]>
                </title>
                <description>
                    <![CDATA[ We are living through an AI revolution. The AI industry is constantly evolving, with new tools, products, and technologies emerging every day. For those not familiar with the AI domain, keeping up with these developments can be challenging. The bigge... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-to-know-about-gpt-4/</link>
                <guid isPermaLink="false">66bd90a1c1ca1df1936e2a03</guid>
                
                    <category>
                        <![CDATA[ Artificial Intelligence ]]>
                    </category>
                
                    <category>
                        <![CDATA[ chatgpt ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kaushal Joshi ]]>
                </dc:creator>
                <pubDate>Thu, 06 Apr 2023 14:15:36 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/gpt-4.gif" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>We are living through an AI revolution. The AI industry is constantly evolving, with new tools, products, and technologies emerging every day.</p>
<p>For those not familiar with the AI domain, keeping up with these developments can be challenging.</p>
<p>The biggest news recently is undoubtedly GPT-4. Everyone from my barber to Twitter influencers wants to know more. My fellow software developers are not an exception. It feels like having FOMO because we aren't up to date with what's going on in the AI realm.</p>
<p>In this article, we will cover everything that we publicly know about GPT-4. So if you're unfamiliar with terms like ChatGPT, GPT-4, OpenAI, and other buzzwords, this is the guide you need to read.</p>
<h2 id="heading-history-of-gpt-until-now">History of GPT Until Now</h2>
<p>OpenAI announced GPT-3 in 2020. It is a language model trained on a massive dataset available on the internet. It can be your friend and answer your queries, help you debug or write code, solve logical and aptitude questions, translate text, and a lot more.</p>
<p>At the end of 2022, the company released a free preview of <a target="_blank" href="https://chat.openai.com/">ChatGPT</a>. It is a AI chat-bot built with GPT-3.5, the successor to GPT-3. ChatGPT soon became the talk of the town (world!). More than a million people signed up for the preview in just five days.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/gdb/status/1599683104142430208?s=20"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p> </p>
<p>In January 2023, Microsoft invested (reportedly) $10 billion in OpenAI. We will discuss why this is important later.</p>
<p>And finally, OpenAI <a target="_blank" href="https://openai.com/research/gpt-4">released</a> GPT-4 in March 2023, which shook the world with its capabilities.</p>
<h2 id="heading-what-is-gpt-4">What is GPT-4?</h2>
<p>"Generative Pre-trained Transformer 4" or GPT-4 is a multimodal Large Language Model (LLM). It is more reliable, creative, and can handle more complex instructions than GPT-3.5. It outperforms every known AI model in every measurement parameter.</p>
<p>GPT-4 is OpenAI's efforts at scaling up deep learning. It is the most capable AI model yet. Though it is less capable than humans in many real-world scenarios, it excels at several professional and academic benchmarks with human-level precision.</p>
<h2 id="heading-availability-of-gpt-4">Availability of GPT-4</h2>
<p>GPT-4 is not available for everyone, unlike ChatGPT. There are several ways you can get access to it:</p>
<ol>
<li><p><a target="_blank" href="https://openai.com/waitlist/gpt-4-api"><strong>API Waitlist</strong></a>: You can sign-up for the waitlist and get rate-limited access to the GPT-4 API</p>
</li>
<li><p><strong>Priority access</strong>: Developers can contribute to <a target="_blank" href="https://github.com/openai/evals">OpenAI Evals</a> and get API access once the contribution is merged.</p>
</li>
<li><p><a target="_blank" href="https://openai.com/blog/chatgpt-plus"><strong>ChatGPT Plus</strong></a>: It is also available for ChatGPT Plus subscribers with a $20 monthly fee.</p>
</li>
<li><p><strong>Microsoft Bing</strong>: It also powers Microsoft's recently revamped Bing Search Engine. It is currently available for selected users.</p>
</li>
<li><p><strong>Third-party Services</strong>: OpenAI has collaborated with several organizations to integrate GPT-4, like Duolingo, Morgan Stanley, and Khan Academy, to name a few.</p>
</li>
</ol>
<h2 id="heading-capabilities-of-gpt-4">Capabilities of GPT-4</h2>
<p>GPT-4 outperforms the majority of humans in various professional and academic benchmarks. The company tested the latest model with the previous one with some of the toughest exams in the world. And GPT-4 excelled at everything thrown to it by significant numbers.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-259.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>comparing GPT-4 with GPT-3.5 in various competitive exams (source: OpenAI)</em></p>
<p>OpenAI published a <a target="_blank" href="https://arxiv.org/abs/2303.08774">technical paper</a> that analyzes this further.</p>
<p>The team spent 6 months making GPT-4 safer and more aligned. GPT-4 is 82% less likely to respond to requests for disallowed content and 40% more likely to produce factual responses than GPT-3.5 on our internal evaluations.</p>
<h2 id="heading-new-and-improved-input-methods">New and Improved Input Methods</h2>
<p>GPT-4 serves user prompts intelligently. It is better at handling large texts and image inputs. It can also change its personality to talk to you!</p>
<h3 id="heading-provide-prompts-up-to-25000-words">Provide prompts up to 25,000 words</h3>
<p>The GPT-3.5 could only handle text entries of up to 3,000 words. GPT-4 goes far beyond this, accepting entries of up to 25,000 words. It can also accept graphical contributions.</p>
<p>Though GPT-4 struggles when dealing with large amounts of data, it is still superior to GPT-3.5. The increased input length will help you to contextualize your prompts more clearly. You can provide entire documents, theses, and webpages as a prompt all at once.</p>
<h3 id="heading-upload-an-image-as-a-prompt">Upload an image as a prompt</h3>
<p>Image inputs are still a research preview yet to be publicly available. As of now, only <a target="_blank" href="https://www.bemyeyes.com/">be my eyes</a> supports the latest image inputs.</p>
<p>Nonetheless, image inputs have identical capabilities and functionalities as text inputs. Users can specify vision or language to get their desired output. It can also be augmented with test-time techniques developed for text-only language models, including few-shot and chain-of-thought prompting.</p>
<p>One more observation about input prompts is that GPT-4 remembers earlier conversations within a single chat session. It can back-reference what it said in the past or bring out what you prompted as well. But it can not remember conversations between different sessions yet.</p>
<h3 id="heading-you-can-change-its-personality">You can change its personality</h3>
<p>I must say, I am fan of this feature. LLMs can change their personalities and behavior as per user prompts. We call it "steerability" in AI.</p>
<p>GPT-3.5 has a fixed personality with predefined vocabulary, tone, and style. Anything that it answers feels the same. With GPT-4, we can describe personalities in the system message. The company explains in its blog that it's easier for ChatGPT to break its character, so the personality is changed only "within bounds".</p>
<p>This is helpful in scenarios where you want the answer to be like a specific personality. You can tell it to be a sympathetic listener, guide, mentor, tutor and so on.</p>
<p>The blog explains steerability by giving an example of a Socratic tutor. The <a target="_blank" href="https://en.wikipedia.org/wiki/Socratic_method">Socratic Method</a> is a discussion between an individual with themselves or others that finds solutions by constantly asking questions and answering them with critical thinking. Using the Socratic method, we can critically think about a complex problem and understand it better.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-22.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-chatgpt-plugins">ChatGPT Plugins</h2>
<p>And when we thought everything was cooling off, OpenAI announced plugins for ChatGPT. Until now, GPT-4 solely relied on its training data, which was last updated in September 2021. It was not connected to the external world.</p>
<p>With plugins, it can access the entire internet. Users can install plugins in their ChatGPT to allow it to access the external world. Now it can interact with real world and updated data to perform various tasks for you.</p>
<p>Plugins can act as "eyes and ears" for LLMs. This allows LLMs to access information unavailable in their training data. This includes data that's too recent, personal, or specific to be included in the training data. Plugins can use such information to produce better, highly accurate, and precise outcomes.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-20.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>11 companies partnering up with OpenAI to build plugins (Source:</em><a target="_blank" href="https://openai.com/blog/chatgpt-plugins"><em>OpenAI Blog</em></a><em>)</em></p>
<p>OpenAI has partnered with 11 companies to create such plugins. Expedia, FiscalNote, Milo, and Zapier are some companies that have already made their plugins. The company also hosts two plugins: a web browser and a code interpreter. It has <a target="_blank" href="https://github.com/openai/chatgpt-retrieval-plugin">open-sourced</a> a knowledge base retrieval plugin.</p>
<p>You can join the waitlist by submitting your interest on its <a target="_blank" href="https://openai.com/waitlist/plugins">website</a>. If you want to read more, I recently wrote a <a target="_blank" href="https://www.showwcase.com/show/34206/chatgpt-has-a-game-changer-update">blog</a> that discusses plugins in detail.</p>
<h2 id="heading-whats-built-with-gpt-4">What's Built with GPT-4?</h2>
<p>There are several tools available today that are built on GPT-4. OpenAI partnered with different companies in two stages. The first stage was for the launch of GPT-4 itself.</p>
<h3 id="heading-microsoft">Microsoft</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-28.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source: Unsplash (Ed Hardie)</em></p>
<p>At the start of the article, I mentioned that Microsoft invested $10 billion in OpenAI. Microsoft is integrating GPT-4 into its existing suite of services, mainly Office-365 and Microsoft Edge. Here is a brief description of every Microsoft tool or service integrated with OpenAI services/GPT-4.</p>
<ol>
<li><p><a target="_blank" href="https://blogs.microsoft.com/blog/2023/02/07/reinventing-search-with-a-new-ai-powered-microsoft-bing-and-edge-your-copilot-for-the-web/"><strong>Copilot for the Web</strong></a><strong>:</strong> Microsoft Bing and Edge have integrated GPT-4 for a better, more complete and creative experience.</p>
</li>
<li><p><a target="_blank" href="https://azure.microsoft.com/en-us/blog/chatgpt-is-now-available-in-azure-openai-service/"><strong>OpenAI in Azure</strong></a><strong>:</strong> ChatGPT is available in preview in Azure OpenAI Service.</p>
</li>
<li><p><a target="_blank" href="https://www.showwcase.com/show/34112/everything-you-need-to-know-about-github-copilot-x"><strong>Copilot X</strong></a><strong>:</strong> GitHub, a Microsoft owned product, also introduced Copilot X that leverages GPT-4 for new features.</p>
</li>
<li><p><a target="_blank" href="https://blogs.microsoft.com/blog/2023/03/16/introducing-microsoft-365-copilot-your-copilot-for-work/"><strong>Copilot for Work</strong></a>: Microsoft introduced Microsoft 365 Copilot, which aims to turn your words into the most powerful productivity tool on the planet.</p>
</li>
</ol>
<h3 id="heading-duolingo">Duolingo</h3>
<p><img src="https://blog.duolingo.com/content/images/2023/02/DuoNews-622x296--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Dulingo Max (Source:</em> <a target="_blank" href="https://blog.duolingo.com/duolingo-max/"><em>Dulingo blog</em></a><em>)</em></p>
<p>Dulingo integrated GPT-4 and launched <a target="_blank" href="https://blog.duolingo.com/duolingo-max/"><strong>Dulingo Max</strong></a><strong>.</strong> It introduces two new features: Explain My Answer and Roleplay. The first explains why user's answers were right or wrong, and provides further examples for better clarification. The latter allows learners to practice real-world conversation skills with world characters in the app.</p>
<h3 id="heading-be-my-eyes">Be My Eyes</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-25.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>source: Internet</em></p>
<p>Be My Eyes is a platform for visually impaired people to help them interpret the world better. GPT-4 acts as a virtual volunteer and analyzes images through GPT-4's image-to-text generator. It doesn't just analyze the content of the image but the context of the image as well.</p>
<h3 id="heading-khan-academy">Khan Academy</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-26.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://www.khanacademy.org/khan-labs"><em>Khan Academy</em></a></p>
<p>Khan Academy is also one of the early adopters of GPT-4. It intends to use GPT-4 as a study and technical assistant. It can help students in exam preparation, improving and practicing vocabulary, and so on. It can also help teachers in administrative tasks, writing lessons and creating lesson hooks, writing exit tickets, and similar tasks.</p>
<h3 id="heading-stripe">Stripe</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-27.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://stripe.com/en-in"><em>Stripe</em></a></p>
<p>Now, Stripe is integrating GPT-4 into its platform. The company already used GPT-3 for simple tasks, but integrating GPT-4 means AI will play a bigger role in the company's processes. It intends to use GPT-4 to streamline the user-experience and add another layer of fraud detection.</p>
<h2 id="heading-what-competitors-are-doing">What Competitors are Doing</h2>
<p>People started using ChatGPT and Microsoft Sydney for their internet searches. Google recognized the imminent threat to their business and acted quickly. The company announced "Bard", its own AI Chatbot that competes with GPT-4.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-19.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://bard.google.com/"><em>Google</em></a></p>
<p>Google Bard is a generative AI chatbot that can produce text responses based on user queries or prompts. Bard uses its own internal knowledge and creativity to generate answers. Bard is powered by a new version of LaMDA, Google's flagship large language model that has been fine-tuned with human feedback.</p>
<p>Bard allows speech inputs along with plain text. It also allows you to make a Google search with the same prompt to verify Bard's answers.</p>
<p>One thing to note here is that Bard constantly reminds us that it is still an experimental model, and it may hallucinate. It also doesn't forget to mention that Google does not support any views and opinions Bard may tell.</p>
<p>Google Bard is currently available in the United States and Britian. You can join the waitlist by visitng <a target="_blank" href="https://bard.google.com/">Bard's official website</a>. I wrote a <a target="_blank" href="https://www.showwcase.com/show/34094/everything-you-need-to-know-about-bard">blog</a> discussing more about Bard. Make sure you read it too.</p>
<h2 id="heading-will-ai-take-your-job">Will AI Take Your Job?</h2>
<p>After reading the entire article, you might feel concerned about your job. OpenAI, OpenReseach, and the University of Pennsylvania published a paper, "<a target="_blank" href="https://arxiv.org/abs/2303.10130"><strong>GPTs are GPTs: An Early Look at the Labor Market Impact Potential of Large Language Model</strong></a>", to analyze the potential impact of such tools on the labor market.</p>
<p>According to the study, 10% of tasks in 80% of US workers can be done by LLMs. For the other ~19% of workers, LLMs could influence at least 50% of tasks. Higher-income jobs will potentially face greater exposure. Programming and writing jobs will also be impacted. On the other hand, jobs that require critical thinking and science are safe. Similarly, jobs with a low barrier to entry are less likely to be impacted.</p>
<p>These jobs are more likely to taken over by AI:</p>
<ul>
<li><p>mathematicians</p>
</li>
<li><p>tax preparers</p>
</li>
<li><p>writers</p>
</li>
<li><p>web designers, programmers</p>
</li>
<li><p>accountants</p>
</li>
<li><p>journalists</p>
</li>
<li><p>legal secretaries</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-17.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>AI will be more likely to take these jobs (Source:</em><a target="_blank" href="https://arxiv.org/abs/2303.10130"><em>Research Paper</em></a><em>)</em></p>
<p>Jobs that are less likely to be impacted by GPT are as follows:</p>
<ul>
<li><p>graphic designers</p>
</li>
<li><p>search marketing strategies</p>
</li>
<li><p>financial managers</p>
</li>
</ul>
<p>The researchers also list LLM's impact on various industries. Industries with the most significant impact are as follows:</p>
<ul>
<li><p>data processing services</p>
</li>
<li><p>information services</p>
</li>
<li><p>publishing industries</p>
</li>
<li><p>insurance carriers</p>
</li>
</ul>
<p>On the other hand, the industries with the most negligible impact are:</p>
<ul>
<li><p>food manufacturing</p>
</li>
<li><p>wood product manufacturing</p>
</li>
<li><p>support manufacturing</p>
</li>
<li><p>agriculture forestry</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-18.png" alt="AI is very unlikely to take these jobs (Source: Research paper)" width="600" height="400" loading="lazy"></p>
<p><em>AI is very unlikely to take these jobs (Source:</em> <a target="_blank" href="https://arxiv.org/abs/2303.10130"><em>Research paper</em></a><em>)</em></p>
<h2 id="heading-epilogue">Epilogue</h2>
<p>If you read all the way through this, give yourself a pat on the back! You have come a long way, and you should know know enough about this crazy buzzword to share your knowledge in meetings and catchups.</p>
<p>I hope you learned something in this overview of ChatGPT. If you did, share it within your networks so that everyone can benefit from it.</p>
<p>Almost every bit of information has been curated from existing announcement blogs, research papers, and content put by official company handles. Still, if you find a mistake or an improvement, please let me know. I would be happy to correct my mistakes.</p>
<p>Let's connect! I want to know what you think about this article. Do you think AI will replace our jobs? Let me know. Here is how you can reach me:</p>
<ul>
<li><p><a target="_blank" href="https://twitter.com/clumsy_coder">Twitter</a></p>
</li>
<li><p><a target="_blank" href="https://kaushaljoshi.dev/">Person</a>al Website</p>
</li>
<li><p><a target="_blank" href="https://www.showwcase.com/clumsycoder">Showwcase</a></p>
</li>
<li><p><a target="_blank" href="https://peerlist.io/kaushal">Peerlist</a></p>
</li>
</ul>
<p>Finally, check out my <a target="_blank" href="https://blog.kaushaljoshi.dev/">personal blog</a>, where I write about front-end development, open-source, technology, and technical writing.</p>
<p>Stay curious! ✨</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build and Push Docker Images to AWS ECR ]]>
                </title>
                <description>
                    <![CDATA[ Docker is a platform that helps you build, run, and ship applications in a seamless and error-free way.  You've likely come across a scenario where the code is running on your machine, but is somehow throwing errors on someone else's machine.  Well, ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-and-push-docker-images-to-aws-ecr/</link>
                <guid isPermaLink="false">66bd9093dc6141cf21aaadb2</guid>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ containers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Docker ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kaushal Joshi ]]>
                </dc:creator>
                <pubDate>Wed, 27 Apr 2022 16:38:22 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/How-to-Build-and-Push-Docker-Images-to-AWS-ECR.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Docker is a platform that helps you build, run, and ship applications in a seamless and error-free way. </p>
<p>You've likely come across a scenario where the code is running on your machine, but is somehow throwing errors on someone else's machine. </p>
<p>Well, Docker was created to solve this very problem.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-166.png" alt="Image" width="600" height="400" loading="lazy">
<em>image source: internet</em></p>
<p>In this article, we will cover four major concepts:</p>
<ol>
<li>How to setup, install, and configure Docker</li>
<li>How to add Docker to your project</li>
<li>How to install and configure AWS CLI on your system</li>
<li>How to use AWS ECR to host a Docker image in a remote location</li>
</ol>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Here's what you'll need to follow along with this tutorial:</p>
<ol>
<li>A Docker account</li>
<li>Basic knowledge of Docker: use case, commands </li>
<li>AWS account</li>
<li>Basic knowledge of AWS: console, IAM, users, ECS, ECR</li>
<li>A simple web app that we can use for this project</li>
</ol>
<p>If you don't have a web app or just want to give it a try, you can clone this project:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://github.com/joshi-kaushal/members-only">https://github.com/joshi-kaushal/members-only</a></div>
<p>The above application is an Express.js application with MongoDB Compass as the database. We will create a Docker image of the project, push it to AWS ECR, and access it through AWS ECS. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-183.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-docker-setup">Docker Setup</h2>
<p>The only thing you need to do if you're using Windows or Mac is install the Docker desktop application. It installs everything you need and gives a nice GUI for interaction.</p>
<p>Go to the <a target="_blank" href="https://www.docker.com/get-started/">official website</a> and install the setup. You also need to create a Docker account for further usage. If you're on Linux, <a target="_blank" href="https://hub.docker.com/search?q=&amp;type=edition&amp;offering=community&amp;operating_system=linux&amp;utm_source=docker&amp;utm_medium=webreferral&amp;utm_campaign=dd-smartbutton&amp;utm_location=module">this page</a> or a simple <a target="_blank" href="https://www.youtube.com/results?search_query=install+docker+on+linux">YouTube</a> search will help you get it done.</p>
<p>To check if the installation is successful, execute <code>docker --version</code> in the terminal. It should prompt with the version and build installed in your system.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-151.png" alt="Image" width="600" height="400" loading="lazy">
<em>Checking if the Docker installation is successful</em></p>
<h3 id="heading-docker-login">Docker Login</h3>
<p>Go to <a target="_blank" href="https://hub.docker.com/signup">hub.docker.com/signup</a> and create your account. To connect your system with your Docker account, execute <code>docker login</code> in the terminal. </p>
<p>You will see <strong>Login succeeded</strong> prompted in the terminal. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-149.png" alt="Image" width="600" height="400" loading="lazy">
<em>Checking if the Docker login is successful</em></p>
<p>Once Docker is installed and configured in your system, let's move to the next section.</p>
<h2 id="heading-how-to-dockerize-your-project">How to Dockerize Your Project</h2>
<p>By <strong>Dockerize</strong><em>,</em> I mean setting up your existing project with Docker and containerizing it. </p>
<p>Create a file named <code>Dockerfile</code> without any extension in the root of your project directory. It contains the code required to build a Docker image and run the dockerized app as a container. </p>
<p>If you are using VS Code, the <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker">Docker</a> extension will come in handy.</p>
<h3 id="heading-how-to-configure-the-dockerfile">How to Configure the Dockerfile</h3>
<p>As a bare minimum configuration, paste the following code in the <code>Dockerfile</code>.</p>
<pre><code>FROM node:<span class="hljs-number">12.17</span><span class="hljs-number">.0</span>

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

ENV PORT=<span class="hljs-number">3000</span>

EXPOSE <span class="hljs-number">3000</span>

CMD [ <span class="hljs-string">"npm"</span>, <span class="hljs-string">"start"</span> ]
</code></pre><p>Before understanding these instructions, create a <code>.dockerignore</code> file and add <code>node_modules</code> in it. It works the same as <code>.gitignore</code>. </p>
<p>Now let's go through that code:</p>
<ul>
<li><code>FROM</code>: Sets the base image for further instructions. For the sake of simplicity, we will use an officially supported Node.js image. I am using the exact version mentioned in my <code>package.json</code>, so change it accordingly if you're using a different node version. </li>
<li><code>WORKDIR</code>: Adds source code from our current working directory to the image.</li>
<li><code>COPY</code>: Copy files and folders from source to destination in the image filesystem. We are copying <code>package.json</code> and <code>package-lock.json</code>. This command ensures that we have a list of dependencies to install in our docker container.</li>
<li><code>RUN</code>: Executes the given command. As we have <code>package.json</code> from the previous step, we can install dependencies in our container. </li>
<li><code>COPY</code>: Now, we are copying everything from project directory to our container. Since both are in the same directory, we are using <code>.</code> which indicates the current working directory. <code>node_modules</code> doesn't get copied since we have added it in <code>.dokcerignore</code>.</li>
<li><code>ENV</code>: Sets an environment variable for the docker container.</li>
<li><code>EXPOSES</code>: When we are running this container, we want to listen our app on a particular port. <code>EXPOSES</code> allows us to access the containerized application publicly. It doesn't need to be the same as <code>ENV</code>, but it reduces complexity :)</li>
<li><code>CMD</code>: There can be only one <code>CMD</code> command in one image, which tells the container how to start the application. Notice we have passed as array and the necessary command as elements. This is called as <strong>exec form</strong> and it allows us to run the command without starting a shell session. </li>
</ul>
<p>We have setup everything we need to create a Docker file. Let's create a Docker image now!</p>
<h3 id="heading-how-to-create-a-docker-image">How to Create a Docker Image</h3>
<p>You use the <code>docker build</code> command to create a build of Docker image. There are a bunch of parameters we can pass with the command. But one we are going to use here is <code>-t</code>. This gives your image a name tag which makes it easy to remember as well as access. </p>
<p>There is no standardized way to name your image, but normally you would see this: Docker user name followed by a slash (<code>/</code>)  and then version number separated by a colon(<code>:</code>). </p>
<pre><code>docker build -t &lt;name-tag&gt; .
</code></pre><p>The second argument is the location of the Dockerfile. Since ours are in the same directory, we can put a period(.).</p>
<p>When you run the command, you will see that steps are being executed in the same order as they are written in the <code>Dockerfile</code>. Once done, it will prompt <strong>Successfully built </strong> in the terminal.</p>
<p>You can use <code>baseID</code> to access the particular Docker image instead of using its name tag.</p>
<p>You can verify this by looking at the <em>Images</em> section in the Docker app. Also you can see the local container in <code>Containers/ Apps</code> section.</p>
<p>For the time being, let's run our Docker image in our local system.</p>
<pre><code>docker run -p <span class="hljs-number">3000</span>:<span class="hljs-number">3000</span> &lt;name-tag&gt;
</code></pre><p>Remember, you can also use <code>&lt;baseID&gt;</code> instead of <code>&lt;name-tag&gt;</code>.</p>
<h3 id="heading-port-forwarding">Port Forwarding</h3>
<p>If you run the above command without <code>-p 3000:3000</code>, you won't see anything on the port 3000. This is because even if we have exposed port 3000 in Dockerfile, if have not made it accessible to the outside world,</p>
<p>The <code>-p</code> flag allows us to do port forwarding from the container to our local machine.</p>
<p>Port forwarding is actually a huge concept, but this is everything we need to know for now. </p>
<p>Visit <a target="_blank" href="http://localhost:3000/"><code>http://localhost:3000/</code></a> in your browser. Well, you have created a Docker container and are running it on your local machine. Kudos!</p>
<p>Usually, you push this image to some kind of container registry to use it in real world scenarios. It could be a Docker Hub or anything else. We are using Amazon Elastic Container Service provided by AWS.</p>
<p>For smooth communication between local Docker image and ECS, we need to set up AWS CLI in our system. Let's see how to do it.</p>
<h2 id="heading-how-to-set-up-aws-cli">How to Set Up AWS CLI</h2>
<p>AWS Command Line Interface is a command line tool that enables us to use AWS resources through our terminal. Anything that we can do in AWS console or web GUI can also be done with CLI.</p>
<p>We have to setup and configure AWS CLI in our system in order to use ECS services locally. To check if you already have AWS CLI installed, execute this command in the terminal:</p>
<pre><code>aws cli
</code></pre><p>If the command doesn't respond with anything, CLI is not configured. If it does, feel free to jump to the next section. </p>
<h3 id="heading-how-to-install-aws-cli">How to Install AWS CLI</h3>
<p>I am using Windows 10 with WSL2. But the procedure is similar for Mac OS and Linux Debian.</p>
<p>Go to <a target="_blank" href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">this</a> website and follow the steps for your distribution. For Windows, you have to download an MSI. Then an installer prompt will show up. Just follow along and it will be installed in a few minutes.</p>
<p>Now restart the terminal and execute <code>aws cli</code> again. Let's setup a user for this local profile.</p>
<h3 id="heading-how-to-set-up-a-local-user-for-aws-cli">How to Set Up a Local User for AWS CLI</h3>
<p>Go to the IAM section of AWS console on the web. Follow this GIF to create a new user:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/ecs-new-user.gif" alt="Image" width="600" height="400" loading="lazy">
<em>create a user with appropriate rights</em></p>
<p><strong>Remember:</strong></p>
<ol>
<li><strong>Access Key - Programmatic Access</strong> is checked when you enter the name of new user.</li>
<li>Add a user policy that gives full access of ECS. The name of the policy is <code>AmazonECS_FullAccess</code>.</li>
<li>Note down <code>access key ID</code> and <code>Secret access key</code>, as we'll have to use these later.</li>
</ol>
<p>Let's go back to our good ol' terminal. Execute the configuration command in the terminal and enter your access key, secret access key, and preferred region. Skip the <code>default output format</code> for now.</p>
<pre><code>aws configure
</code></pre><p>Verify the configuration by executing <code>aws configure list</code> command.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-152.png" alt="Image" width="600" height="400" loading="lazy">
<em>Verifying AWS CLI Configuration</em></p>
<p>Congratulations! We have successfully setup AWS CLI with our local terminal. Now it's time to push our Docker image to Amazon ECR.</p>
<h2 id="heading-aws-elastic-container-services">AWS Elastic Container Services</h2>
<p>It's been so long since we talked about Docker. We have created a local Docker image and container. We have to publish it from our local Docker repository to AWS ECR. It is done through ECS</p>
<p>What is ECS? You might ask.</p>
<blockquote>
<p>Amazon Elastic Container Services aka ECS is a fully managed container orchestration service that makes it easy for you to deploy, manage, and scale containerized applications.</p>
</blockquote>
<p>And Elastic Container Registry or ECR is the registry for Docker containers stored in ECS. We will be using ECS to push our Docker container to ECR.</p>
<h3 id="heading-how-to-create-a-repo-in-ecr">How to Create a Repo in ECR</h3>
<p>For simplicity, I suggest keeping the same name as your project.</p>
<pre><code>aws ecr create-repository --repository-name &lt;repo_name&gt; --region &lt;region_name&gt;
</code></pre><p>If you are not sure about <code>region_name</code>, put <code>us-east-1</code>.  This would create your repo in US EAST-1 region. Once finished, it will prompt a JSON object like response in the terminal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-153.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>For a safer side, check AWS console and see if a repository is created:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/aws-ecr-repo.gif" alt="Image" width="600" height="400" loading="lazy">
<em>verifying if a repo is created</em></p>
<p><strong>Remember:</strong></p>
<ol>
<li>You won't see any images under repository. Because we haven't pushed any image yet.</li>
<li>Note down <code>URI</code> of your repo. We'll have to use it soon.</li>
</ol>
<h3 id="heading-how-to-push-a-docker-image-to-ecr">How to Push a Docker Image to ECR</h3>
<p>Every piece has been individually created so far. It's time to join each and every piece and complete the puzzle. </p>
<p>For Docker to push the image to ECR, first we have to authenticate our Docker credentials with AWS. We use the <code>get-login-password</code> command that retrieves and displays an authentication token using the <em>GetAuthorizationToken</em> API that we can use to authenticate to an Amazon ECR registry.</p>
<pre><code>aws ecr get-login-password --region &lt;region_name&gt;
</code></pre><p>Use the same <code>region_name</code> that you used while creating a repo. Store the encrypted token somewhere for a moment.</p>
<p>Take a deep breath now. We need two things I told you to save somewhere. The first is the token I just mentioned and second is the repository URI from the previous step. </p>
<p>Did you get that? Lessgooo!</p>
<pre><code> aws ecr --region &lt;region&gt; | docker login -u AWS -p &lt;encrypted_token&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">repo_uri</span>&gt;</span></span>
</code></pre><p>Needless to say, put the same region where your repository exists.</p>
<p>We are querying the ECR API provided by AWS CLI. Later we are pipelining Docker login.</p>
<ul>
<li><code>-u AWS</code>: Default user provided by AWS.</li>
<li><code>-p &lt;encrypted_token&gt;</code>: Password we retrieved in the last step.</li>
<li><code>repo_uri</code>: URI of our repository.</li>
</ul>
<p>If the login is successful, <strong>Login Succeeded</strong> will be shown in the terminal. </p>
<h3 id="heading-how-to-tag-a-local-docker-image">How to Tag a Local Docker Image</h3>
<p>This command tags a local Docker image with the ECR Repo.</p>
<pre><code>docker tag &lt;source_image_tag&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">target_ecr_repo_uri</span>&gt;</span></span>
</code></pre><ul>
<li><code>source_image_tag</code>: The name you gave for the <code>docker build</code> command. If you are following along, it is <code>username/image_name:tag</code>.</li>
<li><code>target_ecr_repo_uri</code>: ECR Repository URI.</li>
</ul>
<h3 id="heading-how-to-push-the-docker-image-to-ecr">How to Push the Docker Image to ECR</h3>
<p>The final step – the last piece of the puzzle!</p>
<p>The following command pushes the local Docker file to the remote ECR repository. Depending on the image size, it will take some time to finish.</p>
<pre><code class="lang-bash">docker push &lt;ecr-repo-uri&gt;
</code></pre>
<p>Hurray! We have made it 🎉</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-182.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can see the uploaded image in the AWS console. Go to ECR, click on repositories, and open ECR repo we uploaded a few minutes back. Copy <code>Image URI</code> if you want to use it further. </p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this article, we covered how to deploy a Docker image on AWS ECS. You can use this Docker container resting inside ECR to host your application on the server. It could be AWS EC2 or anything else. </p>
<p>Docker and AWS are widely used to develop large scale applications. Having an idea how these things work together should help you build large scale applications in the future.</p>
<p>Having said that, I hope this article has helped you in your work, studies or learnings. If it did, you might also find my other articles helpful. </p>
<p>I mainly write on my <a target="_blank" href="https://clumsycoder.hashnode.dev/">personal blog</a> and <a target="_blank" href="https://www.freecodecamp.org/news/author/clumsycoder/">freeCodeCamp</a>. If you want to say hi, I am most active on <a target="_blank" href="https://twitter.com/clumsy_coder">Twitter</a>, <a target="_blank" href="https://www.linkedin.com/in/7JKaushal">LinkedIn</a> and <a target="_blank" href="https://www.showwcase.com/clumsycoder">Showwcase</a>.</p>
<p>Happy shipping! 🐳🚢</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Add Diagrams to GitHub Markdown Files ]]>
                </title>
                <description>
                    <![CDATA[ Previously, if you wanted to include a diagram in your GitHub README file, you would've needed to add it like an image created with third-party software.  This worked, and let us complete our tasks – but why settle for less when you can create a diag... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-diagrams-to-github-readme/</link>
                <guid isPermaLink="false">66bd909a2384aa6dc0878d6a</guid>
                
                    <category>
                        <![CDATA[ GitHub ]]>
                    </category>
                
                    <category>
                        <![CDATA[ markdown ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kaushal Joshi ]]>
                </dc:creator>
                <pubDate>Thu, 17 Feb 2022 16:37:07 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/02/How-to-Add-Diagrams-to-GitHub-Markdown-Files.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Previously, if you wanted to include a diagram in your GitHub README file, you would've needed to add it like an image created with third-party software. </p>
<p>This worked, and let us complete our tasks – but why settle for less when you can create a diagram within the README file itself? Well, now you can.</p>
<p>On February 14th, GitHub gifted a new feature to all <em>devlovers</em>. Mermaid syntax is now supported by default in GitHub Markdown. This means that we can now create and edit diagrams in the native markdown file.</p>
<p>But first, what is Mermaid?</p>
<h2 id="heading-what-is-mermaid">What is Mermaid? 🧜‍♀️</h2>
<p><a target="_blank" href="https://mermaid-js.github.io/">Mermaid</a> is a tool that renders diagrams based on markdown-like text content. It helps us visualize documentation and catch it up with development by dynamically creating and modifying diagrams in the browser. </p>
<p>Mermaid supports various types of diagrams, such as UML diagrams, Gantt charts, Git Graphs, and User Journey Diagrams.</p>
<h2 id="heading-how-does-mermaid-work">How Does Mermaid Work? 🤔</h2>
<p>According to the official GitHub blog, when a code block marked as <code>mermaid</code> is encountered, the raw mermaid syntax in the block is passed to Mermaid.js and an iframe is generated. The iframe is injected into the page, pointing <code>src</code> to the Viewscreen service. Viewscreen is GitHub's internal file rendering service which is partially responsible for this whole process.</p>
<p>The entire process is explained well in the official announcement blog. Here's a representation of how the Mermaid code block is dynamically rendered in the browser:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645105817746/kgxkzcsoY.png" alt="github-mermaid-working.png" width="679" height="555" loading="lazy">
<em>rendering Mermaid code</em></p>
<h2 id="heading-mermaid-demo">Mermaid Demo 🧐</h2>
<p>To integrate Mermaid in your README, you don't need to add any external thing whatsoever! You just have to make a code block with the <code>mermaid</code> language designation.</p>
<p>But don't worry – you don't need to learn a new language or script. If you have an idea about markdown and supported diagrams, you won't find it too hard to get started.</p>
<p>Sounds simple? Let's make a user journey diagram of me studying for exams.</p>
<p>In your GitHub Web, open any markdown file. Paste the below code into the write section and hit preview.</p>
<pre><code class="lang-mermaid">
</code></pre>
<p>journey
    title Me studying for exams
    section Exam is announced
        I start studying: 1: Me
        Make notes: 2: Me
        Ask friend for help: 3: Me, Friend
        We study togther: 5: Me, Friend
    section Exam Day
        Syllabys is incomplete: 2: Me
        Give exam: 1: Me, Friend
    section Result Declared
        I passed the exam with destinction!: 5: Me
        Friend barely gets passing marks: 2: Friend</p>
<pre><code>
</code></pre><p>Don't forget to enclose it in code blocks and add <code>mermaid</code> at the beginning.<br>Like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645109309368/yQ6EyCj7E.png" alt="image.png" width="307" height="123" loading="lazy"></p>
<p>When rendered, it will look something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1645105399104/PCryqtntS.png" alt="github-mermaid-demo.png" width="1714" height="494" loading="lazy">
<em>User Diagram created with Mermaid in GitHub README</em></p>
<blockquote>
<p>Fun fact: The sequence diagram depicting the rendering Mermaid syntax above is also rendered with the new feature. You can find the code <a target="_blank" href="https://gist.github.com/martinwoodward/8ad6296118c975510766d80310db71fd">here</a>.</p>
</blockquote>
<h2 id="heading-final-words">Final Words 👋</h2>
<p>Mermaid integration allows you to keep your diagrams close to the documentation, saving time and effort spent managing a separate software. </p>
<p>You can read the original GitHub blog <a target="_blank" href="https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/">here</a> or have a look at <a target="_blank" href="https://mermaid-js.github.io/">Mermaid</a>'s official documentation.</p>
<h2 id="heading-before-we-end">Before We End ✨</h2>
<p>I was inspired to write this article because I was eager to try out this feature as soon as I heard about its release. I hope you found this article helpful. I have my own <a target="_blank" href="https://clumsycoder.hashnode.dev/">personal blog</a> where I talk about web development and my experiences.</p>
<p>My DMs are always open if you want to say hello. I am most active on <a target="_blank" href="https://twitter.com/clumsy_coder">Twitter</a>, <a target="_blank" href="https://www.linkedin.com/in/7JKaushal/">LinkedIn</a>, and <a target="_blank" href="https://www.showwcase.com/">Showwcase</a>. See you there!</p>
<p>Till then, happy documenting! 📃</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
