<?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"><channel><title><![CDATA[Afraz's DevBlog]]></title><description><![CDATA[Aspiring polyglot, learning and getting better each day.]]></description><link>https://afrazmomin.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 12:53:33 GMT</lastBuildDate><atom:link href="https://afrazmomin.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Secure your Cloud Infrastructure with tfsec]]></title><description><![CDATA[With the growing complexity of infrastructure deployments, security vulnerabilities can unavoidably creep into your Terraform configurations. In this blog post, we will explore how tfsec can help us identify and address security issues in Terraform c...]]></description><link>https://afrazmomin.com/secure-infrastructure-with-tfsec</link><guid isPermaLink="true">https://afrazmomin.com/secure-infrastructure-with-tfsec</guid><category><![CDATA[AWS]]></category><category><![CDATA[Terraform]]></category><category><![CDATA[Security]]></category><category><![CDATA[Devops]]></category><category><![CDATA[DevSecOps]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Sun, 16 Apr 2023 00:00:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1690935147362/1b8ab6e7-f031-4462-9e25-995f7b5c8c8e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>With the growing complexity of infrastructure deployments, security vulnerabilities can unavoidably creep into your Terraform configurations. In this blog post, we will explore how <code>tfsec</code> can help us identify and address security issues in Terraform code through a practical example.</p>
<h3 id="heading-what-is-tfsec">What is tfsec?</h3>
<p>Tfsec is an open-source static analysis tool developed specifically for Terraform. Its main objective is to scan your Terraform code and identify potential security risks and misconfigurations in your codebase. By running <code>tfsec</code> against your Terraform files, you can proactively detect vulnerabilities, ensuring that your infrastructure is built on a solid foundation of security best practices.</p>
<h4 id="heading-example-scenario-creating-an-aws-s3-bucket">Example Scenario: Creating an AWS S3 Bucket</h4>
<p>Let's consider a simple example of creating an AWS S3 bucket using Terraform. Below is the Terraform configuration for our S3 bucket:</p>
<pre><code class="lang-plaintext">provider "aws" {
  region = "us-west-2"
}

resource "aws_s3_bucket" "example_bucket" {
  bucket = "example-bucket"
  acl    = "private"

  tags = {
    Name        = "Example Bucket"
    Environment = "Production"
  }
}
</code></pre>
<p>In this example, we are creating an S3 bucket named <code>example-bucket</code> in the <code>us-west-2</code> AWS region. The bucket is set to private access, additionally, we've added some tags to the bucket.</p>
<h4 id="heading-running-tfsec">Running tfsec</h4>
<p>Before running tfsec, ensure you have Terraform and tfsec installed on your machine. Once everything is set up, open your terminal and navigate to the directory containing the Terraform configuration.</p>
<p>Now, run the following command to analyze the Terraform file with tfsec:</p>
<pre><code class="lang-bash">tfsec example_bucket.tf
</code></pre>
<p>Tfsec will analyze the configuration and provide a report on potential security issues. In our example, tfsec would give us an output similar to the following:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">WARNING:</span> <span class="hljs-string">S3</span> <span class="hljs-string">bucket</span> <span class="hljs-string">has</span> <span class="hljs-string">an</span> <span class="hljs-string">ACL</span> <span class="hljs-string">defined</span> <span class="hljs-string">which</span> <span class="hljs-string">allows</span> <span class="hljs-string">public</span> <span class="hljs-string">read</span> <span class="hljs-string">access.</span>
  <span class="hljs-attr">File:</span> <span class="hljs-string">example_bucket.tf:6</span>

<span class="hljs-attr">WARNING:</span> <span class="hljs-string">S3</span> <span class="hljs-string">bucket</span> <span class="hljs-string">has</span> <span class="hljs-literal">no</span> <span class="hljs-string">server-side</span> <span class="hljs-string">encryption</span> <span class="hljs-string">defined.</span>
  <span class="hljs-attr">File:</span> <span class="hljs-string">example_bucket.tf:6</span>
</code></pre>
<h4 id="heading-interpreting-the-tfsec-results">Interpreting the tfsec Results</h4>
<p>From the tfsec output, we can see that it has identified two security issues in our Terraform configuration:</p>
<ol>
<li><p>Public Read Access: The S3 bucket is configured with an "acl" attribute set to "private," but tfsec is warning us that the configuration still allows public read access.</p>
</li>
<li><p>Lack of Server-Side Encryption: The S3 bucket does not have server-side encryption (SSE) enabled, which poses a potential security risk for sensitive data stored in the bucket.</p>
</li>
</ol>
<h4 id="heading-addressing-the-findings">Addressing the findings</h4>
<p>Now that we have identified the issues, let's take steps to address them:</p>
<ol>
<li>Resolving Public Read Access:</li>
</ol>
<p>To restrict public access, we need to update the S3 bucket's configuration to deny public read access explicitly. We can achieve this by adding a "block_public_acls" attribute to the resource block.</p>
<blockquote>
<p>Please note that the AWS Terraform Provider version used for the examples below is not the latest. Syntax varies in the latest version, especially, for the S3 resources.</p>
</blockquote>
<p>The updated Terraform configuration will look like this:</p>
<pre><code class="lang-plaintext">resource "aws_s3_bucket" "example_bucket" {
  bucket = "example-bucket"
  acl    = "private"

  block_public_acls = true

  tags = {
    Name        = "Example Bucket"
    Environment = "Production"
  }
}
</code></pre>
<ol>
<li>Implementing Server-Side Encryption:</li>
</ol>
<p>To enable server-side encryption, we can set the "server_side_encryption_configuration" attribute within the "aws_s3_bucket" resource block. The updated Terraform configuration will look like this:</p>
<pre><code class="lang-plaintext">resource "aws_s3_bucket" "example_bucket" {
  bucket = "example-bucket"
  acl    = "private"

  block_public_acls = true

  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        sse_algorithm = "AES256"
      }
    }
  }

  tags = {
    Name        = "Example Bucket"
    Environment = "Production"
  }
}
</code></pre>
<blockquote>
<p>Just a reminder again that the AWS Terraform Provider version used for the example above is not the latest. Please refer to the provider documentation for the latest updates.</p>
</blockquote>
<p>With these changes, we have addressed the security issues identified by tfsec in our Terraform configuration.</p>
<h3 id="heading-tfsec-with-pre-commit-hooks-and-ci">Tfsec with Pre-commit Hooks and CI</h3>
<p>Integrating tfsec into pre-commit hooks and Continuous Integration (CI) pipelines ensures that security checks are performed automatically at different stages of the development process. Let's go through the steps to integrate tfsec in both scenarios.</p>
<h4 id="heading-integrating-tfsec-in-pre-commit-hooks">Integrating tfsec in Pre-Commit Hooks:</h4>
<p>Pre-commit hooks are scripts that run before each commit is made in your version control system. By adding tfsec as a pre-commit hook, you can prevent developers from committing Terraform code that violates security best practices.</p>
<p>Step 1: Install tfsec and Pre-commit</p>
<p>Ensure that tfsec and pre-commit are installed on your local machine. You can install pre-commit using a package manager like pip (for Python projects) or your OS's package manager.</p>
<p>Step 2: Create the Pre-commit Configuration File</p>
<p>In your Terraform project's root directory, create a file named <code>.pre-commit-config.yaml</code>. This file will define the pre-commit hooks and the tools to use for validation.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">repos:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">repo:</span> <span class="hljs-string">https://github.com/liamg/tfsec</span>
    <span class="hljs-attr">rev:</span> <span class="hljs-string">&lt;tfsec_version&gt;</span>  <span class="hljs-comment"># Replace &lt;tfsec_version&gt; with the desired version or use "master" for the latest.</span>

<span class="hljs-attr">hooks:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">id:</span> <span class="hljs-string">tfsec</span>
    <span class="hljs-attr">name:</span> <span class="hljs-string">tfsec</span>
    <span class="hljs-attr">stages:</span> [<span class="hljs-string">commit</span>]
    <span class="hljs-attr">types:</span> [<span class="hljs-string">terraform</span>]
</code></pre>
<p>Step 3: Install Pre-commit Hooks</p>
<p>After creating the <code>.pre-commit-config.yaml</code> file, run the following command to install the pre-commit hooks:</p>
<pre><code class="lang-bash">pre-commit install
</code></pre>
<p>Now, every time you attempt to make a commit, pre-commit will automatically execute tfsec on your Terraform files, preventing commits with security issues.</p>
<ol>
<li>Integrating tfsec in Continuous Integration (CI) Pipelines:</li>
</ol>
<p>Incorporating tfsec into your CI pipeline allows you to perform security checks on your Terraform code whenever changes are pushed to the repository. We'll use an example with GitLab CI, but the steps can be adapted for other CI/CD systems.</p>
<p>Step 1: Create <code>.gitlab-ci.yml</code></p>
<p>In your project's root directory, create a <code>.gitlab-ci.yml</code> file if it doesn't already exist. This file defines the pipeline stages and jobs to be executed in CI.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">stages:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-string">test</span>

<span class="hljs-attr">tfsec_scan:</span>
  <span class="hljs-attr">stage:</span> <span class="hljs-string">test</span>
  <span class="hljs-attr">image:</span> <span class="hljs-string">liamg/tfsec:latest</span>  <span class="hljs-comment"># Use the tfsec Docker image</span>
  <span class="hljs-attr">script:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">tfsec</span>  <span class="hljs-comment"># Run tfsec against Terraform files</span>
</code></pre>
<p>Step 2: Push and Trigger CI Pipeline</p>
<p>Commit and push the <code>.gitlab-ci.yml</code> file to your GitLab repository. This will trigger the CI pipeline, and tfsec will be executed to scan your Terraform code for security issues.</p>
<p>You can adapt this example to other CI/CD systems like Jenkins, Travis CI, CircleCI, or GitHub Actions by configuring the CI pipeline to run tfsec using their specific syntax.</p>
<p>Now, every time you attempt to make a commit, pre-commit will automatically execute tfsec on your Terraform files, preventing commits with security issues.</p>
<h4 id="heading-wrapping-up">Wrapping Up</h4>
<p>Tfsec is an invaluable tool for enhancing the security of your Terraform infrastructure. In our example, we saw how using a simple tool we were able to successfully to detect public read access and the absence of server-side encryption in our S3 bucket configuration before they became significant risks, allowing us to take appropriate corrective measures.</p>
<p>By integrating tfsec in both pre-commit hooks and CI pipelines, you ensure that Terraform code is continuously checked for security issues throughout the development process. Pre-commit hooks prevent insecure code from being committed, while CI pipelines catch security problems early, before changes are merged into the main branch.</p>
<p>By adopting these practices, you can enhance the security of your Terraform infrastructure and prevent security vulnerabilities from slipping into your production environments. Happy Terraforming!</p>
<hr />
<p><strong>If you liked what you read, do consider sharing the article with a friend and connect with me on Twitter -</strong> <a target="_blank" href="https://twitter.com/afraz_momin"><strong>@afraz_momin</strong></a><strong>. Also, subscribe to my newsletter and stay up-to-date with my latest blog posts.</strong></p>
]]></content:encoded></item><item><title><![CDATA[Managing Repetitive Infrastructure with for_each and count in Terraform]]></title><description><![CDATA[As the infrastructure grows in complexity, the need to deploy multiple instances of the same resource becomes imminent. Terraform offers two looping techniques, for_each and count, to tackle this. In this blog post, we explore how these techniques ca...]]></description><link>https://afrazmomin.com/managing-repetitive-terraform</link><guid isPermaLink="true">https://afrazmomin.com/managing-repetitive-terraform</guid><category><![CDATA[AWS]]></category><category><![CDATA[Terraform]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Wed, 07 Dec 2022 00:59:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1690935250313/efdf281a-a7da-45e1-85ab-48f1bf3b12bc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As the infrastructure grows in complexity, the need to deploy multiple instances of the same resource becomes imminent. Terraform offers two looping techniques, <code>for_each</code> and <code>count</code>, to tackle this. In this blog post, we explore how these techniques can be used to manage repetitive infrastructure with ease.</p>
<p><strong>1.</strong> <code>count</code><strong>:</strong></p>
<p><code>count</code> is a simple yet powerful inbuilt feature in Terraform that allows you to duplicate resources based on a numeric value. It is ideal for scenarios where you know the exact number of resource instances you need to create. For instance, deploying multiple identical EC2 instances for load balancing or autoscaling purposes.</p>
<pre><code class="lang-hcl">resource "aws_instance" "example" {
  count         = 3
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}
</code></pre>
<p>In this example, Terraform will create three EC2 instances with the specified AMI and instance type. We can update the <code>count</code> value to any other number to change the number of instances accordingly.</p>
<p><strong>2.</strong> <code>for_each</code><strong>:</strong></p>
<p>While <code>count</code> is great for a fixed number of resources, but it falls short when dealing with dynamic or variable-driven infrastructure. Here is when <code>for_each</code> comes into the picture, as it is more flexible and suited for use cases where you need to create resources based on data structures such as maps or sets.</p>
<pre><code class="lang-hcl">variable "ec2_instances" {
  type = map(object({
    ami           = string
    instance_type = string
  }))
  default = {
    instance1 = {
      ami           = "ami-0c55b159cbfafe1f0"
      instance_type = "t2.micro"
    }
    instance2 = {
      ami           = "ami-0c55b159cbfafe1f0"
      instance_type = "t2.small"
    }
  }
}

resource "aws_instance" "example" {
  for_each = var.ec2_instances

  ami           = each.value.ami
  instance_type = each.value.instance_type
}
</code></pre>
<p>In this example, we define a variable <code>ec2_instances</code> as a map of objects containing AMI and instance type details. By using <code>for_each</code>, Terraform creates two EC2 instances based on the data provided in the variable. This way, we can easily add or remove instances by updating the map.</p>
<p><strong>3. When to use what -</strong> <code>count</code> <strong>or</strong> <code>for_each</code> <strong>?</strong></p>
<p>The decision to use <code>count</code> or <code>for_each</code> depends on your infrastructure requirements. If you know the exact number of resources you need, <code>count</code> is a straightforward choice. However, if you want greater flexibility and intend to create resources based on dynamic input, <code>for_each</code> is the way to go.</p>
<p><strong>4. A few points to note:</strong></p>
<p>Keep in mind that while <code>count</code> and <code>for_each</code> are powerful tools, they can have implications on your Terraform state and resource management. Changing the value of <code>count</code> or the keys within a <code>for_each</code> map can lead to resource destruction or recreation. Therefore, it's important to be cautious when modifying these configurations in production environments.</p>
<p>In conclusion, Terraform's <code>for_each</code> and <code>count</code> are essential features for managing repetitive infrastructure effectively. With <code>count</code>, you can easily duplicate resources a fixed number of times, while <code>for_each</code> provides the flexibility to create resources based on dynamic input. With these looping techniques, infrastructure automation becomes a cakewalk, allowing you to focus on building complex but robust infrastructure.</p>
<hr />
<p><strong>If you liked what you read, do consider sharing the article with a friend and connect with me on Twitter -</strong> <a target="_blank" href="https://twitter.com/afraz_momin"><strong>@afraz_momin</strong></a><strong>. Also, subscribe to my newsletter and stay up-to-date with my latest blog posts.</strong></p>
]]></content:encoded></item><item><title><![CDATA[Simplifying Dynamic blocks in Terraform]]></title><description><![CDATA[When I started out with Terraform, dynamic blocks were a tough nut for me to crack, atleast for a while. For some reason, reading the official documentation repeatedly didn't help my case. In this article, I have tried my best to explain the dynamic ...]]></description><link>https://afrazmomin.com/simplifying-dynamic-blocks</link><guid isPermaLink="true">https://afrazmomin.com/simplifying-dynamic-blocks</guid><category><![CDATA[Terraform]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Sat, 20 Aug 2022 23:56:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1690935173445/fbe2385d-23e8-4c1a-a49b-d47ec4c99a54.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When I started out with Terraform, dynamic blocks were a tough nut for me to crack, atleast for a while. For some reason, reading the official documentation repeatedly didn't help my case. In this article, I have tried my best to explain the dynamic blocks in Terraform in simple language with examples that will make it easier to understand for anyone starting out with Terraform.</p>
<p>Traditional Terraform code often involves specifying resource blocks with fixed, static configurations. For example, creating multiple security group rules or IAM policies for different instances can lead to repetitive and lengthy code. Dynamic Blocks help in addressing this challenge as they offer a more clean approach to managing such scenarios.</p>
<p>Dynamic Blocks enable Terraform to create multiple instances of a particular configuration block within a single resource or data block which is dynamically generated based on variables or a collection of elements. This means that instead of repeating the same configuration multiple times, we can loop through a list or map to generate the required blocks automatically.</p>
<h3 id="heading-syntax">Syntax :</h3>
<p>The syntax for Dynamic Blocks consists of the keyword <code>dynamic</code>, followed by one or more nested <code>for_each</code> or <code>for</code> expressions, and inside it, we define the block type along with its arguments.</p>
<p>Assuming you have already set up your AWS provider configuration, let's start by defining the variables and the listener configuration map in a Terraform file called <a target="_blank" href="http://variables.tf"><code>variables.tf</code></a> :</p>
<pre><code class="lang-hcl">variable "elb_name" {
  description = "Name of the Elastic Load Balancer"
  type        = string
}

variable "listener_rules" {
  description = "Map of listener rules for the Elastic Load Balancer"
  type        = map(object({
    protocol           = string
    load_balancer_port = number
    instance_protocol  = string
    instance_port      = number
  }))
}
</code></pre>
<p>In this example, <code>listener_rules</code> is a map that can hold multiple listener configurations. Each configuration contains the following attributes:</p>
<ul>
<li><p><code>protocol</code>: The protocol for the incoming traffic (e.g., HTTP, HTTPS, TCP).</p>
</li>
<li><p><code>load_balancer_port</code>: The port on the Elastic Load Balancer that listens for incoming traffic.</p>
</li>
<li><p><code>instance_protocol</code>: The protocol to use when forwarding traffic from the load balancer to the backend instances (e.g., HTTP, HTTPS, TCP).</p>
</li>
<li><p><code>instance_port</code>: The port on the backend instances that the load balancer forwards traffic to.</p>
</li>
</ul>
<p>Now, let's create the main Terraform configuration file (e.g., <a target="_blank" href="http://main.tf"><code>main.tf</code></a>) to provision the ELB using Dynamic Blocks:</p>
<pre><code class="lang-hcl">provider "aws" {
  region = "us-west-2"  # Replace with your desired AWS region
}

resource "aws_elb" "example" {
  name      = var.elb_name
  subnets   = ["subnet-12345678", "subnet-87654321"]  # Replace with your subnet IDs
  listener {
    instance_port     = 80
    instance_protocol = "HTTP"
    lb_port           = 80
    lb_protocol       = "HTTP"
  }

  dynamic "listener" {
    for_each = var.listener_rules

    content {
      instance_port     = listener.value.instance_port
      instance_protocol = listener.value.instance_protocol
      lb_port           = listener.value.load_balancer_port
      lb_protocol       = listener.value.protocol
    }
  }
}
</code></pre>
<p>In this configuration, we create an Elastic Load Balancer resource (<code>aws_elb</code>) with a default listener configured on port 80 for HTTP traffic. Other than that, we use the Dynamic Block to create additional listeners based on the configurations provided in the <code>listener_rules</code> map.</p>
<p>For example, you can define the listener_rules in a separate <code>.tfvars</code> file (e.g., <code>variables.tfvars</code>):</p>
<pre><code class="lang-hcl">listener_rules = {
  "https_listener" = {
    protocol           = "HTTPS"
    load_balancer_port = 443
    instance_protocol  = "HTTP"
    instance_port      = 80
  }
  "custom_tcp_listener" = {
    protocol           = "TCP"
    load_balancer_port = 8080
    instance_protocol  = "TCP"
    instance_port      = 8080
  }
}
</code></pre>
<p>With this configuration, the Terraform code will dynamically create two additional listeners in the Elastic Load Balancer, as defined in the <code>listener_rules</code> map. If you need to add more listeners, simply include them in the map with their respective configurations.</p>
<p>By leveraging Dynamic Blocks, you can easily manage and scale your infrastructure configurations with minimal code repetition, making your Terraform codebase more clean, maintainable, and readable.</p>
<hr />
<p><strong>If you liked what you read, do consider sharing the article with a friend and connect with me on Twitter -</strong> <a target="_blank" href="https://twitter.com/afraz_momin"><strong>@afraz_momin</strong></a><strong>. Also, subscribe to my newsletter and stay up-to-date with my latest blog posts.</strong></p>
]]></content:encoded></item><item><title><![CDATA[Introduction to Container Orchestration]]></title><description><![CDATA[Containerization made an entrance in the DevOps landscape when Docker was launched in 2013. Even though the fundamental concept of containerization existed before Docker, it was the first time people on a large scale were introduced to the idea of ru...]]></description><link>https://afrazmomin.com/introduction-to-container-orchestration</link><guid isPermaLink="true">https://afrazmomin.com/introduction-to-container-orchestration</guid><category><![CDATA[containers]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Sun, 15 May 2022 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1655321570487/g7ivpnfxx.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Containerization made an entrance in the DevOps landscape when Docker was launched in 2013. Even though the fundamental concept of containerization existed before Docker, it was the first time people on a large scale were introduced to the idea of running applications inside a container.</p>
<p>If you have a number of apps to run, as you likely do if you have migrated to the cloud, containers come in handy. They make it easy to turn apps on and off to meet changing demands. They also let you move apps seamlessly between different servers. But at the same time, containers come with their own set of complexities which can get out of hand without proper management.</p>
<p>To do all of this you need a management platform which can spin containers up, suspend them or shut them down when needed. Ideally, they should also control how the containers access resources like network and data storage. This is where orchestration platforms provide us with a solution to this piece of the puzzle. Orchestration provides us with a number of features like provisioning hosts, instantiating a set of containers, rescheduling failed containers, linking them together through agreed interfaces, exposing services to the outside world and of course, scaling up or down by adding or removing the containers.  </p>
<p>In this article, you will learn in-depth about </p>
<ul>
<li>What is Container Orchestration? And why is it needed?</li>
<li>History of Container Orchestration</li>
<li>How does it work? </li>
<li>Benefits and Drawbacks</li>
<li>What are the top container orchestration tools available today?</li>
</ul>
<h2 id="heading-what-is-container-orchestration">What is Container Orchestration?</h2>
<p>Container orchestration is an automated and simplified process of managing every aspect of individual containers and their dynamic environments. It is nothing but an automated approach to the deployment, scaling and networking of the containers.</p>
<h3 id="heading-why-do-you-need-container-orchestration">Why do you need container orchestration?</h3>
<p>Let's assume you have a web application and a database running on two different containers. With time, the traffic to your web app increases, and it is not able to manage this load. As a response to this, you decide to scale the web-app server by adding a few more container instances of the web app across multiple hosts. Similarly, the database container will also be needed to scale accordingly. Adding new containers seems reasonable if the amount is small, but what happens when you have to deal with the addition of a much higher container count, like in hundreds or more?</p>
<p>Also, how do you decide which container goes on which host? Or how do you determine the number of containers you need to run per host? What happens if a container is using too much memory? How do you identify the health of each container? In case some container turns out to be unhealthy, how do you replace the failed container?  Do you want a mechanism to replace this container automatically?
Last but not the least, how do you ensure security and access for these containers?</p>
<p>This is where Container Orchestration platforms come into the picture.</p>
<h2 id="heading-history-of-container-orchestration-how-did-we-get-here-and-why">History of Container Orchestration - how did we get here and why?</h2>
<p>There has been a huge shift in trend from using monolithic architecture to microservices in recent years. This rise of microservices-based architecture caused increased usage of container technologies. Containers act as the perfect host for small independent applications like microservices. This led to applications having hundreds or sometimes even thousands of containers running at the same time. Managing these loads of containers across multiple environments using scripts and self-made tools can be complex and time-consuming. This demand for a proper way of managing these hundreds of containers caused the need for container orchestration technologies.</p>
<h2 id="heading-how-does-container-orchestration-work">How Does Container Orchestration Work?</h2>
<p>Depending on the orchestration platform being used, there can be different techniques to implement container orchestration. Generally, these platforms work based upon the user-created JSON or YAML files which describe the configuration of the application. Most orchestration platforms support declarative configurations.</p>
<p>These configuration files prompt the orchestration platform on how to pull the container images, how to link containers through a network, how to mount storage volumes and where to store log data. </p>
<p>Container orchestration tools also help with the deployment scheduling of containers into clusters and can detect the most appropriate host for the deployment. This host is selected on the basis of guidelines, labels or metadata provided in the configuration files. Once selected, the container orchestration platforms use predefined guidelines to look after the container throughout its lifecycle.</p>
<h2 id="heading-benefits">Benefits</h2>
<p>Container orchestration aid in managing the container lifecycles in large environments. They simplify container management. Container Orchestration can provide software teams with the following capabilities - </p>
<ul>
<li><p><strong>Improved application deployment</strong> - 
Container orchestration tools can scale applications up and down with minimal manual intervention. This results in high performing applications. Container orchestration tools can also help in spreading application load evenly across the containers.</p>
</li>
<li><p><strong>Improved Productivity</strong> - 
With container orchestration in place, software teams can rapidly test, deploy, patch and scale as and when needed.</p>
</li>
<li><p><strong>Better Security</strong> -
As applications in containers run in an isolated environment, it ensures better security. Besides with container orchestration tools, communication between different services can be set restrictively, allowing only certain services to communicate to and fro as well as, only specific types of services to be exposed to the outside world.</p>
</li>
<li><p><strong>Reduced costs and resource needs</strong> - 
Multiple containers can be provisioned inside the same host. Containers are lightweight and do take up much space as an OS image normally would. Besides, container orchestration tools can be used to manage these resources more efficiently, ultimately reducing the overall cost to be incurred by the organization.</p>
</li>
<li><p><strong>Microservices</strong> - 
Each microservice can be provisioned on different containers and with the help of container orchestration tools they can be scaled or modified independently, as and when needed. With the help of orchestration platforms, microservices can communicate more fluidly with each other within the cluster.</p>
</li>
</ul>
<p>These are some of the benefits that container orchestration platforms offer.</p>
<h2 id="heading-drawbacks">Drawbacks</h2>
<p>Container Orchestration tools have turned out to be a boon for many organizations but they come with their set of cons as well. Here are some of them - </p>
<ul>
<li><strong>Overkill for simple applications</strong> - 
Container orchestration can be an overkill for simple applications. If you do not intend to build anything complex which will be accessed by thousands of users at the same time or deploy an app with high computing resource needs, container orchestration would be highly unideal.</li>
<li><strong>Complexity</strong> - 
Container orchestration platforms come with their own level of complexities. Developers, who do not come from an infrastructure background, can have a tough time figuring out stuff with the orchestration platforms. </li>
<li><strong>Transition to orchestration platforms can be challenging</strong> - 
Adoption of orchestration platforms can require some effort. It can be difficult to gauge this effort as use-cases for every organization would be different. It also depends on various other factors like - which programming language is being used and what is the desired environment for that application to run? Or is the application already containerized?</li>
<li><strong>Expensive compared to other methods</strong> - 
Container orchestration can be quite cheaper if used correctly but it can turn out to be quite expensive as well if the above-mentioned drawbacks are not taken care of. As discussed, migrating or deploying small applications to these orchestration platforms may not be wise and will take up a lot of your engineering time. So besides the infrastructure cost, you will also incur this indirect cost.</li>
</ul>
<h2 id="heading-top-orchestrators-present-in-the-market">Top Orchestrators present in the Market</h2>
<p>The top 3 widely used options for Container Orchestration vary in implementation and how you interact with them. Here are some brief descriptions of the platforms and a list of top companies that have adopted them - </p>
<h3 id="heading-kubernetes">Kubernetes</h3>
<p>Kubernetes or also known as K8S is an open-source container orchestration tool, which was originally developed by Google. It is by far one of the most popular open-source projects to take the IT world by storm. It seems like almost everywhere you go, every news article you read, or blog you encounter, tells a story of how Kubernetes has revolutionized the way DevOps and IT infrastructure work, like no other platform before it. </p>
<p>Started as an internal project by Google at first, Kubernetes has the capability of deploying, managing, configuring, and orchestrating at both small and large scales. Kubernetes, one can easily run containerized applications across multiple clustered
nodes, automatically maintaining the desired number of replicas, service endpoints,
and load-balancing across the cluster.</p>
<p>Some top companies using Kubernetes - </p>
<ul>
<li>Google</li>
<li>Spotify</li>
<li>Pinterest</li>
</ul>
<h3 id="heading-docker-swarm">Docker Swarm</h3>
<p>Docker Swarm is Docker's very own container orchestration tool. It gives you the easiest route for orchestrating a cluster of Docker hosts. Docker Swarm comes packaged with Docker which makes it simplest to configure. Docker Swarm has a low learning curve and is very simple to use, making it the best choice for the deployment of smaller applications.</p>
<p>Those wanting to leverage extensive features of Kubernetes while using Docker Swarm can opt for the Docker Enterprise Edition which offers a bundle of both the tools. Docker Swarm supports Windows and Mac OS X but uses VMs to run on non-Linux systems. So if an application is deployed on a Windows container, it won't be able to run on a Linux system. Kubernetes has an upper hand in this as it is not operating system specific.</p>
<p>Some top companies using Docker Swarm -</p>
<ul>
<li>Apple</li>
<li>Mozilla</li>
<li>Wells Fargo</li>
</ul>
<h3 id="heading-apache-mesos">Apache Mesos</h3>
<p>Developed at UC Berkeley, Mesos has gained huge popularity among large organizations like Twitter, eBay, Airbnb and Paypal. It has a very lightweight interface and can provide support for multiple programming languages. Mesos is known for providing flexible architectures and high scalability, owing to the ability to scale to a large number of nodes within the infrastructure. </p>
<p>Ironically, Mesos is not a <code>container orchestration</code> tool. It is in fact a cluster management tool. Mesos, when combined with a framework called <code>Marathon</code>, can work as a proper container orchestrator. Although Mesos promises a lot of scale, it comes with a lot of complexity. It has a steep learning curve and requires high technical expertise. This is the reason why Mesos is only widely adopted by large-scale organizations and may be unideal for small companies that have a limited number of resources.</p>
<p>Some top companies using Apache Mesos -</p>
<ul>
<li>Airbnb</li>
<li>Twitter</li>
<li>eBay</li>
</ul>
<p>In the end, which container orchestration tool you use will depend on the scalability that you want to achieve and in which ecosystem you and your organization feel the most comfortable.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>To sum up, container orchestration helps us automate the process of deploying and managing containers in bulk. It simplifies container lifecycle management in large environments, offering developers improved agility with their systems and helping them deploy applications to the cloud much faster and with more efficiency. For organizations which reply on the deployment of their applications on containers and require them to scale, container orchestration is very valuable and of the utmost importance.</p>
<hr />

<p><strong>If you liked what you read, do consider sharing the article with a friend and connect with me on Twitter - <a target="_blank" href="https://twitter.com/afraz_momin">@afraz_momin</a>. Also, subscribe to my newsletter and stay up-to-date with my latest blog posts.</strong></p>
]]></content:encoded></item><item><title><![CDATA[Debouncing v/s Throttling: What's the difference?]]></title><description><![CDATA[Website performance plays a huge role in enhancing the user experience of our websites. In this article, we will learn about performance optimization techniques like Debouncing and Throttling and the key difference between them.
Debouncing and Thrott...]]></description><link>https://afrazmomin.com/debouncing-vs-throttling</link><guid isPermaLink="true">https://afrazmomin.com/debouncing-vs-throttling</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[100DaysOfCode]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Tue, 29 Sep 2020 08:30:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1601344992592/uZkYP_HLv.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Website performance plays a huge role in enhancing the user experience of our websites. In this article, we will learn about performance optimization techniques like Debouncing and Throttling and the key difference between them.</p>
<p>Debouncing and Throttling are widely-used techniques that help us in limiting the rate at which a function fires off. These two techniques give us a layer of control between the event and the execution of the functions attached to them. API servers often implement either of these two techniques to prevent the application from being overloaded. </p>
<p>These function calls could be anything from a simple scroll event to an API call to the server. Both these techniques are almost identical and help us reduce the number of function calls being made but they have one small, but significant difference among them. </p>
<p>Before we get into the difference, let's understand how they work individually -</p>
<h3 id="what-is-debouncing">What is Debouncing?</h3>
<p>Debouncing is a technique in which no matter how many times a user fires an event, 
the call will be made only after a specific amount of time has passed <strong>after the user stops firing the event.</strong></p>
<p>For example, let's say a user is typing something in a search box. This search box makes API calls and has a debounce function attached to it with a specified time duration of 400ms. So now, unless 400ms have passed after the user stopped typing, the API call wouldn't be made. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1601131218693/oxlreiYn1.gif" alt="debouncing.gif" /></p>
<p>I wrote a detailed article on Debouncing in Javascript, a couple of months ago. If the concept of debouncing is completely new to you, I strongly suggest you go to the link below and read the post before moving ahead with this one.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://blog.afrazmomin.com/debouncing-in-javascript">https://blog.afrazmomin.com/debouncing-in-javascript</a></div>
<h3 id="what-is-throttling">What is Throttling?</h3>
<p>Throttling is a technique that makes the next function call strictly after a certain period of time. No matter how many times the user fires an event, the function attached will be <strong>executed only once in the given time period.</strong> </p>
<h4 id="lets-understand-this-by-coding-a-simple-throttle-function-ourselves">Let's understand this by coding a simple throttle function ourselves -</h4>
<p>We will start by taking a simple Button. Let's say this button calls some API. The <code>onclick</code> attribute on this button will call two functions - <code>normalFunc()</code> and <code>apiWithThrottle()</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1601304916777/IXISBvKc2.png" alt="image.png" /></p>
<p>In our Javascript file, we'll define the functions -</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1601198395398/VEnG_lef1.png" alt="carbon.png" /></p>
<p>The <code>normalFunc()</code> keeps track of the number of clicks made on the button, and <code>apiCallFunc()</code> keeps track of the number of API calls being made. The function <code>apiWithThrottle()</code> when triggered by the button, will call the <code>throttle()</code> function in which the function to be throttled and the time limit are given as parameters.</p>
<h4 id="after-running-this-code-we-see-something-like-this">After running this code, we see something like this -</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1601302138430/2VOWXDLv1.gif" alt="second.gif" /></p>
<p>Here, we have set the time limit to 1 second (1000ms). Notice how the user clicks the button multiple times but the call to the API is only made 3 times, each after an interval of 1 second. To sum it up in simple words - even if the user clicks the button 15 times in 3 seconds, the number of times the API call will be made is 3 only. </p>
<blockquote>
<p>Here's the link to the <a target="_blank" href="https://codepen.io/afrazchelsea/pen/ZEWZZzP?__cf_chl_jschl_tk__=0179b83d2f4126274a036af65c94852eb166cd86-1601352909-0-AXFNLTphxkHBsmCGyeIIV4X53_DUqUBsuUqwuDJo2hEXdw_PljihEnXNP-F7czffsK8uEmpyESR3J4i3DaiMUK-Ud_I3r0fZV8SN4K91Wq6E1_dyGaKA-BQrU2MeI_wl_SubktUz2xPIf-BV7SQqXSLI9mBgRQYmkff0xGVEor8jZYWXV4xxMImy6zjOgkMAK5vMgxE63fpldBX5DUbfrgJNKOe1qRIotDd9GL2g-vX5ooy4ztqTEombA1an1Hg7WEy6gCWAJN9wOm2YzsWmeROuN_aYeC7KzZ1iA7KG_vi-uDY2_onbDJIgvjazYnyDuD3MExodeSq6AYUWeQcH6E8">CodePen</a>, if you want to try this out yourself.</p>
</blockquote>
<h3 id="debouncing-vs-throttling">Debouncing vs Throttling</h3>
<p>The difference between the two can be understood by taking a simple real-life example - </p>
<ul>
<li>Debouncing</li>
</ul>
<p>Imagine you're a 7-year toddler who loves chocolates. You persistently keep asking your mom for some chocolates. She gives you some but then you start asking for some more. You ask her so many times that she gets annoyed and tells you that you can have it only if you don't bother her and remain silent for the next one hour. This means if you keep asking her, you will only get it one hour after the last time you asked her. </p>
<p>This is debouncing.</p>
<ul>
<li>Throttling</li>
</ul>
<p>Consider the same example - You ask your mom for chocolates despite having them a few minutes ago. You persistently keep asking her, she gets annoyed and finally decides to give you some. But she, being your mom, knows that you will ask for some more in a few minutes. So she gives you the chocolates with a condition that you won't get any more for the next one hour. You still keep bothering her for more but now she ignores you. Finally, after an hour has passed, she gives you the chocolates. If you ask for more, you will get it only after an hour, no matter how many times you ask her.</p>
<p>This is what throttling is!</p>
<h4 id="use-cases">Use-cases</h4>
<p>Both these techniques have their own set of use-cases. </p>
<p>Debouncing can be used when the result of the most recent event occurrence is what is important. For example, a search query on an e-commerce website. </p>
<p>Throttling can be used when the input provided to the function call doesn't matter or is the same each time. For example, infinite scrolling on a webpage. Here, we need to check how far the user is from the bottom of the page. If they're too close, we request more data and append it to the page. Here debouncing wouldn't work as it would only trigger the event when the user has stopped scrolling but we need to start fetching the content before the user reaches the bottom.</p>
<p>Another example would be a multiplayer fighting game where your character has to punch to defeat its opponent. Throttling can be applied to this punching ability of the character such that it can punch only once per second. Now even if the player gives the command to punch 10 times in 5 seconds, the number of punches thrown would be 5 only.</p>
<h3 id="wrapping-up">Wrapping Up</h3>
<p>Techniques like debouncing and throttling give us control over the execution of events in our websites, helping us reduce the number of high computational tasks that may hamper the performance of our website. They might have different use-cases but the end goal remains the same i.e better performance. So if you're a developer looking to optimize your website, you know what to do!</p>
<hr />

<p><strong>If you liked what you read, share the article with a friend and connect with me on Twitter - <a target="_blank" href="https://twitter.com/afraz_momin">@afraz_momin</a>. Also, subscribe to my newsletter and stay up-to-date with my latest blog posts. I plan to write similar articles on Javascript in the coming days!</strong></p>
]]></content:encoded></item><item><title><![CDATA[Function Currying in JavaScript]]></title><description><![CDATA[Javascript is a multi-paradigm language that allows you to freely mix and match object-oriented, procedural, and functional paradigms. Recently there has been a growing trend towards functional programming. The functional programming style not only a...]]></description><link>https://afrazmomin.com/function-currying-in-javascript</link><guid isPermaLink="true">https://afrazmomin.com/function-currying-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Functional Programming]]></category><category><![CDATA[DevBlogging]]></category><category><![CDATA[100DaysOfCode]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Sat, 29 Aug 2020 10:30:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598373111465/z9K0pCs1L.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Javascript is a multi-paradigm language that allows you to freely mix and match object-oriented, procedural, and functional paradigms. Recently there has been a growing trend towards functional programming. The functional programming style not only attempts to pass functions as arguments, a.k.a callbacks, but also returns back functions as well. This feature of functional programming gives us many new and useful concepts. One of these concepts is Currying.</p>
<p>In this article, we will take a look at what currying is and how it helps us make our code clean and much simpler.</p>
<h2 id="what-is-currying">What is Currying?</h2>
<p>Before diving into currying, we first need to understand the <em>arity</em> of a function. The <em>arity</em> of a function is basically the number of arguments it requires. </p>
<p>Consider these two examples -</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addTwo</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a+b;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addThree</span>(<span class="hljs-params">a, b, c</span>) </span>{
  <span class="hljs-keyword">return</span> a + b + c; 
}
</code></pre><p>In this case, the arity of the function <code>addTwo</code> is 2 and the arity of the function <code>addThree</code> is 3. </p>
<p>Currying a function means to convert a function of N arity into N different functions of arity 1.</p>
<p><strong> In much simpler words, currying is the process of restructuring the function so that it takes only one argument and then returns another function that takes the next argument, and so on. </strong></p>
<p>To give you a sense of how this could work, let's create a couple of functions -</p>
<pre><code><span class="hljs-comment">// Un-curried function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x + y;
}

<span class="hljs-comment">// Curried function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addCurried</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">y</span>) </span>{
    <span class="hljs-keyword">return</span> x + y;
  }
}

add(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);  <span class="hljs-comment">// Returns 3</span>
addCurried(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>);  <span class="hljs-comment">// Returns 3</span>
</code></pre><p>Notice the difference between the two. The first function is a simple function that takes two parameters -  <code>a</code> and <code>b</code>, and adds them. On the other hand, the second function <code>addCurried</code> takes only one argument i.e <code>a</code>, and returns another function which takes <code>b</code> as the argument. Both give us the same result.</p>
<p>Currying can be helpful when we can't provide all arguments to a function at one time.</p>
<p>Each function call can be saved into a variable, which will hold the returned function reference that takes the next argument when it's available. Let's take another example to understand this better -</p>
<pre><code><span class="hljs-comment">// Curried function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params">msg</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">name</span>) </span>{
    <span class="hljs-built_in">console</span>.log(msg, name);
  };
}

<span class="hljs-keyword">let</span> english = greet(<span class="hljs-string">"Hello,"</span>);
<span class="hljs-keyword">let</span> spanish = greet(<span class="hljs-string">"Hola,"</span>);
<span class="hljs-keyword">let</span> german = greet(<span class="hljs-string">"Geuten Tag,"</span>);

german(<span class="hljs-string">"Dwight"</span>); <span class="hljs-comment">// Prints "Geuten Tag, Dwight"</span>

spanish(<span class="hljs-string">"Oscar"</span>); <span class="hljs-comment">// Prints "Hola, Oscar"</span>

english(<span class="hljs-string">"Michael"</span>); <span class="hljs-comment">// Prints "Hello, Michael"</span>
english(<span class="hljs-string">"Jim"</span>); <span class="hljs-comment">// Prints "Hello, Jim"</span>
</code></pre><p>Notice how currying helps us avoid passing the same variable again and again. In this case, the variable <code>msg</code>, which will print  "Hello" when called using <code>english</code>. This is a great strategy to avoid frequently calling a function with the same argument.</p>
<h3 id="es6-pattern">ES6 Pattern</h3>
<p>Currying is part of functional programming and such curried functions can also be easily written using the arrow function syntax in ES6 for more cleaner and elegant code in the following way :</p>
<pre><code><span class="hljs-keyword">const</span> addCurried = <span class="hljs-function"><span class="hljs-params">x</span> =&gt;</span> y =&gt; x + y;

addCurried(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>);   <span class="hljs-comment">// Returns 3</span>
</code></pre><h3 id="partial-application-function">Partial Application Function</h3>
<p>When we talk about currying, the concept of Partial Application Function is bound to come up. Currying and Partial application function are almost identical concepts with one significant difference.</p>
<p>Partial application function is a function that returns another function but each returned function can take multiple arguments. In currying, the returning function can only take one argument.</p>
<p>Let's take a simple example to demonstrate this difference- </p>
<pre><code><span class="hljs-comment">// Curried function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addCurried</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">y</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">z</span>) </span>{
      <span class="hljs-keyword">return</span> x + y + z;
    };
  };
}

<span class="hljs-comment">// Partial Application function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addPartial</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">y, z</span>) </span>{
    <span class="hljs-keyword">return</span> x + y + z;
  };
}

addCurried(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>)(<span class="hljs-number">3</span>); <span class="hljs-comment">// Returns 6</span>
addPartial(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>); <span class="hljs-comment">// Returns 6</span>
</code></pre><p>The implementation of both these concepts totally depends upon the use-case and the availability of the arguments at that point in time. But they definitely help us write more cleaner and elegant code.</p>
<h3 id="wrapping-up">Wrapping Up</h3>
<p>Currying is an incredibly useful concept when it comes to functional programming with Javascript. As seen, using currying we can have functions that are more definite in what they do, avoiding potential repetition in our code, which ultimately leads to simplification of our code.</p>
<p><strong> If you liked what you read, connect with me on Twitter - <a target="_blank" href="https://twitter.com/afraz_momin">@afraz_momin</a>.
I plan to write similar articles on JavaScript in the coming days! </strong></p>
]]></content:encoded></item><item><title><![CDATA[Event Bubbling and Event Capturing in Javascript]]></title><description><![CDATA[The interactivity of our HTML web page is handled by Javascript. This interactivity is nothing but a bunch of events that the HTML elements undergo. An event can be something the browser does or something a user does. They tell us some change has hap...]]></description><link>https://afrazmomin.com/event-bubbling-and-event-capturing-in-javascript</link><guid isPermaLink="true">https://afrazmomin.com/event-bubbling-and-event-capturing-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[events]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Sat, 04 Jul 2020 11:15:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603395542235/1tpX431kr.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The interactivity of our HTML web page is handled by Javascript. This interactivity is nothing but a bunch of events that the HTML elements undergo. An event can be something the browser does or something a user does. They tell us some change has happened and where it has happened. It could an onClick event that indicates something has been clicked. Another instance could be an onSubmit event that says that the form has been submitted.</p>
<p>How well these events are handled decide how user-friendly the web page is. </p>
<p>Event Bubbling and Event Capturing are two phases of event propagation/flow in Javascript. Event flow is basically the order in which the events are received on a web page. In Javascript, event flow takes place in three phases - </p>
<ol>
<li>Capture Phase</li>
<li>Target Phase</li>
<li>Bubble Phase</li>
</ol>
<p>This propagation is bidirectional, from the window to the target and back. What differentiates these phases is the type of listeners that are called. </p>
<p>Let's start by understanding Bubbling first.</p>
<h2 id="event-bubbling">Event Bubbling:</h2>
<p>Bubbling is the flow of events where, when an event takes place on an element, it first runs the handler on itself, then on its parent and then on all of its ancestors.</p>
<p>It basically moves up the hierarchy from the innermost element to the outermost element. </p>
<p>This can be better understood by taking an example -</p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"grandparent"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Grandparent<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"parent"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Parent<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"child"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Child<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">"history.go(0)"</span>&gt;</span>
      Reset Elements
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre><p>In our HTML file, we take 3 divs nested one inside the other and give them ids of <code>child</code>, <code>parent</code>, and <code>grandparent</code> starting from the innermost div. </p>
<h4 id="add-a-bit-of-styling">Add a bit of styling</h4>
<pre><code><span class="hljs-selector-tag">div</span> {
  <span class="hljs-attribute">min-width</span>: <span class="hljs-number">75px</span>;
  <span class="hljs-attribute">min-height</span>: <span class="hljs-number">75px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">25px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid black;
}

<span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
}
</code></pre><p>We will set a <code>click</code> event on each of the 3 divs in our JS file</p>
<pre><code><span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#grandparent"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#grandparent &gt; p"</span>).textContent =
    <span class="hljs-string">"Grandparent Clicked!"</span>;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Grandparent Clicked"</span>);
});

<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#parent"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#parent &gt; p"</span>).textContent = <span class="hljs-string">"Parent Clicked!"</span>;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Parent Clicked"</span>);
});

<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#child"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#child &gt; p"</span>).textContent = <span class="hljs-string">"Child Clicked!"</span>;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Child Clicked"</span>);
});
</code></pre><h4 id="the-code-above-will-perform-in-the-following-way">The code above will perform in the following way -</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1593269603296/jIPWMOyme.gif" alt="first.gif" /></p>
<p>Notice how, even when the <code>child</code> div is clicked, the handlers on all its ancestors get triggered as well. Similarly, when the <code>parent</code> div is clicked, the handler on the <code>grandparent</code> div will get fired as well. But, keep in mind, in this example, the handler on the <code>child</code> div won't be triggered. </p>
<p>Although, what's more important here is the way the event flow happened. It started from the innermost element, i.e. is the <code>child</code> div and then propagated up the hierarchy eventually reaching the <code>parent</code> and <code>grandparent</code> divs (in that order strictly).</p>
<p>This type of flow of events is called Event Bubbling.</p>
<h2 id="event-capturing">Event Capturing:</h2>
<p>The capturing principle is the exact opposite of bubbling.
In Event Capturing, the event propagation takes place from the outermost element to the innermost element. Event capturing is sometimes also referred to as <strong>event trickling</strong>.</p>
<p>We often use the <code>addEventListener()</code> when working with Javascript, in which we usually pass two parameters - </p>
<ul>
<li><p>the event</p>
</li>
<li><p>the callback function</p>
</li>
</ul>
<p>The <code>addEventListener()</code> function also takes a 3rd hidden parameter - <code>useCapture</code> which takes a boolean value. This <code>useCapture</code> parameter is set to default by false. Setting it to false, makes our events propagate using the principle of Bubbling. Setting it to true will make them propagate in a top-down approach, that is, Capturing.</p>
<p>To implement event capturing we will make a few small changes to our JS code - </p>
<pre><code><span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#grandparent"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#grandparent &gt; p"</span>).textContent =
    <span class="hljs-string">"Grandparent Clicked!"</span>;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Grandparent Clicked"</span>);
},<span class="hljs-literal">true</span>); <span class="hljs-regexp">//</span> useCapture parameter <span class="hljs-keyword">is</span> now set to <span class="hljs-literal">true</span>

<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#parent"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#parent &gt; p"</span>).textContent = <span class="hljs-string">"Parent Clicked!"</span>;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Parent Clicked"</span>);
},<span class="hljs-literal">true</span>); <span class="hljs-regexp">//</span> useCapture parameter <span class="hljs-keyword">is</span> now set to <span class="hljs-literal">true</span>

<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#child"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#child &gt; p"</span>).textContent = <span class="hljs-string">"Child Clicked!"</span>;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Child Clicked"</span>);
},<span class="hljs-literal">true</span>); <span class="hljs-regexp">//</span> useCapture parameter <span class="hljs-keyword">is</span> now set to <span class="hljs-literal">true</span>
</code></pre><p>Now our code will run in the following way  -</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1593269619661/0n9fcRgPd.gif" alt="second.gif" /></p>
<p>Notice how the flow of events now propagates from the outermost element to the innermost element.</p>
<p>i.e <code>grandparent</code> -&gt; <code>parent</code> -&gt; <code>child</code></p>
<p>This flow of events is called Event Capturing.</p>
<h4 id="wrapping-up">Wrapping Up</h4>
<p>The reason I spoke about bubbling first is because event capturing is rarely used. It is set to false by default. For most of the browsers, Event bubbling is the default way of event flow.</p>
<p>Javascript helps us make interactive web applications. It makes use of a lot of user-generated events in doing so. The user experience of a website depends on how well these events are handled. Hence it is important to know how events work and the flow behind them. </p>
<p>Here's the link to the  <a target="_blank" href="https://codepen.io/afrazchelsea/pen/abdpqgy?editors=1000">Codepen</a>, if you want to demonstrate this yourself.</p>
<p><strong>If you liked what you read, follow me on Twitter - <a target="_blank" href="https://twitter.com/afraz_momin">@afraz_momin</a> to stay updated.
I plan on writing similar articles about JavaScript in the coming days!</strong></p>
]]></content:encoded></item><item><title><![CDATA[Debouncing in JavaScript]]></title><description><![CDATA[Often situations arise, when we want a certain event to fire off only after a certain amount of time has passed. The most common example would be the search bars we see on e-commerce websites like Amazon or Flipkart. In these search bars, when you ty...]]></description><link>https://afrazmomin.com/debouncing-in-javascript</link><guid isPermaLink="true">https://afrazmomin.com/debouncing-in-javascript</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Mon, 22 Jun 2020 06:50:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603394825032/65APyRpiJ.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Often situations arise, when we want a certain event to fire off only after a certain amount of time has passed. The most common example would be the search bars we see on e-commerce websites like Amazon or Flipkart. In these search bars, when you type something, an API call is made, and results similar to your query are displayed on the screen.</p>
<p>Now imagine making an API call every time a key is pressed on your keyboard. Doesn't sound viable right? Firing an event continuously (in this case, the call to the API) would hamper the performance of the website.</p>
<p>This can be avoided by using the concept of debouncing. Debouncing limits the rate at which a function fires off. In the example above, it drastically reduces the number of API calls that are made to the server.</p>
<p>The setTimeout function of Javascript plays a vital role in implementing debouncing. For those who don't know what setTimeout does, it is a scheduling function provided by Javascript which allows us to run a task after a certain interval of time.</p>
<h4 id="lets-see-how-we-can-implement-debouncing-with-a-simple-example">Let's see how we can implement debouncing with a simple example,</h4>
<p>The very first thing we'll do here is - create a simple input in our HTML file. On this input box, we will call a method <code>searchData()</code> for the <code>onkeyup</code> event. So that every time the user releases the key after pressing it, <code>searchData()</code> is called.</p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"search"</span>&gt;</span>Search<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">onkeyup</span>=<span class="hljs-string">"searchData()"</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"script.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre><p>In our Javascript file, we'll define the <code>searchData()</code> function and create a counter to track the number of times it gets called.</p>
<pre><code><span class="hljs-keyword">let</span> counter = <span class="hljs-number">1</span>; <span class="hljs-comment">// To track number of calls</span>

<span class="hljs-keyword">const</span> searchData = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-comment">// Let's say this function calls some API and gets us some data</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Looking for data.."</span>, counter++);
};
</code></pre><h4 id="after-running-this-program-we-see-something-like-this">After running this program, we see something like this -</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1592509132273/zPQonjL7A.gif" alt="first.gif" /></p>
<p>Notice how for every letter of the word "Michael", the function gets called. Imagine firing off API calls for a bigger query on a much bigger site. That would be very browser intensive and may hinder the performance. To reduce these continuous function calls, we'll make use of the debounce function :</p>
<pre><code><span class="hljs-keyword">let</span> counter = <span class="hljs-number">1</span>; <span class="hljs-comment">// To track number of calls</span>

<span class="hljs-keyword">const</span> searchData = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-comment">// Let's say this function calls some API and gets us some data</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Looking for data.."</span>, counter++);
};

<span class="hljs-comment">// Debounce function</span>
<span class="hljs-keyword">const</span> debounce = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fn, delay</span>) </span>{
  <span class="hljs-keyword">let</span> timer = <span class="hljs-number">0</span>;  
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">clearTimeout</span>(timer); 
    timer = <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> {
      fn();
    }, delay);
  };
};

<span class="hljs-keyword">const</span> callDebounce = debounce(searchData, <span class="hljs-number">300</span>);
</code></pre><p>Note that we make a change in our HTML file and will be calling <code>callDebounce()</code> now instead of <code>searchData()</code></p>
<pre><code> &lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">type</span>="text" onkeyup="callDebounce()" /&gt;
</code></pre><h4 id="the-code-above-will-do-the-following">The code above will do the following -</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1592511364053/fNxHJIJGF.gif" alt="second-final.gif" /></p>
<p>Notice how no call is made until a delay of 300ms is encountered. Instead of making more than a dozen calls for each letter in "Michael Scott", our input bar will only make calls whenever the delay between two keypresses is more than 300 milliseconds. In this case, 2 times.</p>
<p>When the user enters the first character "M", <code>debounce()</code> is triggered which waits for 300ms to fire off the <code>searchData()</code> function. But before 300ms have passed, the user enters another character which will wait another 300ms to fire off <code>searchData()</code> and so on. This will create multiple copies of the timer running in the background. So to clear out the timers in cases where consecutive keypresses are being made without a pause 300ms, we make use of the inbuilt <code>clearTimeout()</code> function. This sets the <code>timer</code> to 0.</p>
<p>This goes on until the user takes a pause after completing the word "Michael", this pause is noticed by the function which in turn fires off our <code>searchData()</code> function.</p>
<p>In simple words, what happens here is that the function waits 300 milliseconds after the last keypress. Only when 300ms have passed and no keypress has been made, it fires off the <code>searchData()</code> function.</p>
<h3 id="wrapping-up">Wrapping Up</h3>
<p>This was a simple demonstration of debouncing. Using this we can reduce the number of calls made several times in succession by a function, which will ultimately lead to an improvement in the performance of our website.</p>
<p><strong> If you liked what you read, consider following me on Twitter - <a target="_blank" href="https://twitter.com/afraz_momin">@afraz_momin</a>  to stay updated. I plan on writing similar articles about JavaScript in the coming days! </strong></p>
]]></content:encoded></item><item><title><![CDATA[React vs Vanilla JS - When to use what?]]></title><description><![CDATA[Web apps can be complex and may require a lot of dynamic functionalities. One can opt for Vanilla JS to build their applications but if you have worked with Vanilla JS before, you know how messy it can get. Here's when JS frameworks like, React, Angu...]]></description><link>https://afrazmomin.com/react-vs-vanilla-js</link><guid isPermaLink="true">https://afrazmomin.com/react-vs-vanilla-js</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[100DaysOfCode]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Thu, 14 May 2020 18:58:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603393962106/xSb1ZD3dt.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Web apps can be complex and may require a lot of dynamic functionalities. One can opt for Vanilla JS to build their applications but if you have worked with Vanilla JS before, you know how messy it can get. Here's when JS frameworks like, React, Angular and Vue, come into the picture.</p>
<p>In this article, I'll walk you through the main differences between a JS library like React and plain Javascript - when to choose which and why?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598701832347/nU1hNGz_w.jpeg" alt="joke.jpg" /></p>
<p>Let's start by answering two simple questions.</p>
<h3 id="what-is-vanilla-js">What is Vanilla JS?</h3>
<p>Vanilla JS is nothing but plain JS without any external libraries or frameworks. Using this we can build powerful and cross-platform applications.</p>
<h3 id="what-is-react">What is React?</h3>
<p>React is a Javascript library used for building user interfaces. It allows us to make complex UIs from isolated pieces of code called "components".</p>
<p>React has quickly become one of the most popular Javascript libraries. This is entirely because of its flexibility and the improvement it brings in the performance. React breaks down the UI into smaller and reusable components that can move around data amongst each other. This breaking down of the UI is what gives React an edge over Vanilla JS.</p>
<p>In Vanilla JS, the code becomes very difficult to maintain if the application is large because in such cases the UI needs to be updated regularly. Here, to change a UI element you need to first find the element in the DOM and then update it. This is fine when you have to update only a single element but imagine doing this on long-form which a user needs to fill. This could be very memory and browser intensive.</p>
<p>This is where React comes in with a great feature i.e its own virtual DOM. The virtual DOM is a shortcut to bypass the manual work. It is a lightweight copy of the actual DOM. It has the same properties as the real DOM but lacks the power to make changes on the screen.</p>
<p>The most important and fundamental reason why modern frameworks are used is that, <strong>with Vanilla JS, keeping the UI in sync with the state is hard</strong>.</p>
<h3 id="lets-understand-this-by-taking-an-example">Let's understand this by taking an example</h3>
<p><em>Consider Facebook. Say at a given time, your friends comment on a picture of yours and you want to see it immediately. You'd want to shift from liking posts to commenting or sharing without being slowed down.</em></p>
<p>Now, this can be done in Vanilla JS too, but the number of changes you'd have to do in the code would be very tedious. All this tiresome work can be avoided by using something like React.</p>
<p>Basically, with React, we can manage to keep <strong>the UI and the state synchronized with each other</strong>. In Vanilla JS, if you have to change the state, you would need to update the UI. One small mistake and your UI could be out of sync with your data.</p>
<p>Code organization and re-use is another important aspect of React. A component created only once can be used multiple times with different data.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Whether you should use Vanilla JS or React depends very much on your use case.</p>
<p>Vanilla JS is awesome but it's not a great alternative when it comes to building huge applications with complex dynamic functionalities. Besides, it cannot create complex and efficient UIs. So if you have an app that changes frequently and drastically with thousands of pages, it is better to use a modern Javascript framework.</p>
<p>On the other hand, React which allows us to use reusable components and is capable of keeping the UI in sync with the state, can definitely solve this problem.</p>
<p>If you liked this post, consider subscribing to my newsletter.</p>
<p>Thanks for reading!</p>
]]></content:encoded></item><item><title><![CDATA[Web Development in 2020 (Front-End)]]></title><description><![CDATA[Hello there!
If you're a beginner in web development OR someone who's looking to get into web development, well, the search is over. You found me!
In this article, I'll be writing and listing out the technologies, frameworks, and libraries which you ...]]></description><link>https://afrazmomin.com/web-development-in-2020-front-end</link><guid isPermaLink="true">https://afrazmomin.com/web-development-in-2020-front-end</guid><category><![CDATA[Web Development]]></category><category><![CDATA[Roadmap]]></category><category><![CDATA[100DaysOfCode]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Afraz Momin]]></dc:creator><pubDate>Sat, 04 Apr 2020 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598701568740/VhoDkkUJL.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello there!</p>
<p>If you're a beginner in web development OR someone who's looking to get into web development, well, the search is over. You found me!</p>
<p>In this article, I'll be writing and listing out the technologies, frameworks, and libraries which you will be needing, to call yourself a web developer in 2020. Most of these are the industry trends at the moment and learning them will only help you find a good job. Along with the different technologies, I'll also be listing out the links to the resources from where you can learn about them. Most of these would be freely available on the internet so I don't know what's stopping you!</p>
<p>Let's get started.</p>
<p>This will be a two-part article (Frontend and Backend). The one you're viewing right now is Part 1.</p>
<p>Before we get started with the technologies, you need to keep in mind that you don't need to learn all of the libraries, technologies, or tools which I'm going to write about below. Pick the ones which attract you. Research a bit about them and get going!</p>
<h3 id="the-basics">The Basics</h3>
<p>HTML/CSS are the building blocks of web development. It's the first you want to learn. No matter which framework you use, you're gonna need HTML and CSS. So as your first step get started with these two. Once well versed, newer CSS tools like Flexbox and Grid are something you'd want to learn next.</p>
<p><strong>Resources :</strong></p>
<ul>
<li><a target="_blank" href="https://www.w3schools.com/">W3Schools</a> - This is the best site to learn HTML/CSS from. Beginner Friendly Content. Covers everything.</li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=vQWlgd7hV4A">HTML CSS Crash Course</a> - If you're too lazy to go through above the link, this crash course by Dev Ed will solve your problems with HTML and CSS, for once and for all.</li>
</ul>
<h3 id="responsive-web-design">Responsive Web Design</h3>
<p>Every project that one creates should look good and completely usable on all devices. Most people use their mobile phones to access a website so it's very important the layout is responsive.</p>
<p>CSS frameworks like Bootstrap and Materialize help in creating excellent responsive webpages. Bootstrap is definitely something I'd recommend to a beginner to style their websites and make it look sharp and clean.</p>
<p>Sass - Sass is a CSS pre-processor. CSS pre-processor? What does that even mean? Well, let's just say it helps you create custom reusable CSS components that you can keep using throughout your project. It's like creating your own mini-framework.</p>
<p><strong>Resources :</strong></p>
<ul>
<li><a target="_blank" href="https://www.youtube.com/watch?v=QAgrHLtG1Yk&amp;list=PL4cUxeGkcC9jE_cGvLLC60C_PeF_24pvv">Bootstrap</a> - This YouTube series by NetNinja will be more than sufficient for you to learn about Bootstrap 4.</li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=nu5mdN2JIwM">Sass</a> - A quick crash course on Sass from Brad Traversy</li>
</ul>
<h3 id="javascript">JavaScript</h3>
<p>Once you're done learning the HTML and CSS, next up is JavaScript or Vanilla Javascript, as some people like to call it. And NO, it's not related to Java in any way.</p>
<p>Javascript is, hands down, the most important thing to learn in web development. It is the language of the browser. It gives your webpage dynamic functionality. For example, altering your web-page after some button is clicked or popping up alert boxes, etc.</p>
<p>Apart from the fundamentals of JS, you must learn things like the DOM (Document Object Model), JSON (JavaScript Object Notation) and FETCH API.</p>
<p>Modern JS (ES6) knowledge is a must before you move on to frameworks like React, Angular or Vue, as they all are basically derivatives of JavaScript itself.</p>
<p><strong>Resources :</strong></p>
<ul>
<li><a target="_blank" href="https://www.udemy.com/course/modern-javascript-from-the-beginning/">Modern Javascript from the Beginning</a> - A Udemy course by Brad Traversy. Good course with multiple projects. Highly Recommended.</li>
</ul>
<h3 id="essential-development-tools">Essential Development Tools</h3>
<p><a target="_blank" href="https://git-scm.com/"> Git (Version Control) </a> / <a target="_blank" href="https://github.com/">Github</a> - Git is something every developer, no matter which domain, should know. Knowing how to create different branches, making pull requests and pushing your code is definitely something you should learn. Github is the most popular platform to do all of this. You can get familiar with Git/Github <a target="_blank" href="https://try.github.io/">here</a>.</p>
<p><a target="_blank" href="https://code.visualstudio.com/">VSCode Extensions</a> - I use VSCode to code my applications and I cannot tell how much these VSCode extensions have made coding easy for me. So if you use VSCode too, I'd recommend extensions like Live Server, Prettier, Bracket colorizer and others ( Maybe another article on this? )</p>
<p>Emmet - Having Emmet will help you write HTML/CSS a lot faster. A MUST HAVE.</p>
<p><a target="_blank" href="https://www.npmjs.com/get-npm">NPM/YARN</a> - NPM (Node Package Manager) and YARN are package managers. There isn't too much to learn here but having some knowledge of these two will help you install packages quickly and speed up the development process.</p>
<p>Apart from all this, Axios is another tool you should take a look at. It is an HTTP library that will make your life easier while working with APIs.</p>
<h3 id="deployment">Deployment</h3>
<p>Deployment these days has been overcomplicated by people. It's not that difficult. We don't really need DevOps or AWS or any other complex platform when we start out.</p>
<p>For personal sites or sites for small businesses, etc. there are managed hosting companies that are easy and cheap.</p>
<p>Two tools that I use regularly are Netlify and Heroku.</p>
<p><a target="_blank" href="https://www.netlify.com/">Netlify</a> - For static hosting. Basically, for web apps with static content where there is no backend involved.</p>
<p><a target="_blank" href="https://www.heroku.com/">Heroku</a> - Being a MERN stack developer, I make use of Heroku to deploy my full-stack applications.</p>
<h4 id="and-voila-youre-a-basic-front-end-developer">And Voila! You're a basic front-end developer</h4>
<p>One might argue to be a Front-end Dev, you need to know a framework. Yup, agreed. But at this point, if you have covered most of the things listed above, believe it or not, you can call yourself a "Basic" Front-end Developer.</p>
<h3 id="front-end-frameworks">Front-End Frameworks</h3>
<p>Frameworks allow us to build single-page applications with organized UIs and more page interactions. These are the 3 most popular front-end frameworks as of today :</p>
<ul>
<li><strong>React</strong> - Maintained by Facebook. Most popular and easy to learn. <em>I prefer React.</em></li>
<li><strong>Vue</strong> - Most recent you could say. Gaining traction. Easy to learn.</li>
<li><strong>Angular</strong> - Maintained by Google. Uses TypeScript.</li>
</ul>
<p>React, Vue or Angular? This is a never-ending debate. You, ultimately, have to make a choice and choose one. I'd say try all three and then pick the one you like.</p>
<p>When it comes to these frameworks, there are also things like server-side rendering (Next.js/Nuxt.js) and static site generation (Gatsby). But they're optional, you don't need to know them right away. It's just a bonus if you know them.</p>
<p><strong>Resources :</strong></p>
<ul>
<li><strong>React</strong> - 1. <a target="_blank" href="https://www.freecodecamp.org/learn/">freeCodeCamp</a> - Best way to learn by doing.<ol>
<li><a target="_blank" href="https://www.youtube.com/watch?v=OxIDLw0M-m0&amp;list=PL4cUxeGkcC9ij8CfkAY2RAGb-tmkNwQHG">NetNinja YouTube Course</a> - React and Redux from Scratch.</li>
</ol>
</li>
<li><strong>Vue</strong> - <a target="_blank" href="https://www.youtube.com/watch?v=5LYrN_cAJoA&amp;list=PL4cUxeGkcC9gQcYgjhBoeQH7wiAyZNrYa">VueJs</a> Youtube Tutorial by NetNinja.</li>
<li><strong>Angular</strong> - <a target="_blank" href="https://www.udemy.com/course/angular-4-front-to-back/">Angular Front to Back</a> - Udemy course by Brad Traversy.</li>
</ul>
<h3 id="conclusion">Conclusion</h3>
<p>By this point, you should be able to build advance front-end apps, interact with APIs and data, manage app and component level states and have smooth front-end workflow.</p>
<p>Summing it up, if you know majority of the stuff I have talked about above, you can call yourself a front-end developer.</p>
<p>Unfortunately, this article only covers the Frontend part of being a full-stack web developer. I'm gonna be writing Part 2, i.e the backend part in another article very soon. Stay tuned !</p>
]]></content:encoded></item></channel></rss>