<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chiamaka Mbah</title>
    <description>The latest articles on DEV Community by Chiamaka Mbah (@saucekode).</description>
    <link>https://dev.to/saucekode</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F73606%2F8a2b9e25-6c41-429f-84a0-7303bbc2993d.jpeg</url>
      <title>DEV Community: Chiamaka Mbah</title>
      <link>https://dev.to/saucekode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saucekode"/>
    <language>en</language>
    <item>
      <title>Automate CI/CD build pipeline for your Springboot app using Jenkins and Github Webhooks</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Sat, 02 Oct 2021 16:49:56 +0000</pubDate>
      <link>https://dev.to/saucekode/automate-ci-cd-build-pipeline-for-a-springboot-app-using-jenkins-and-github-webhooks-3h30</link>
      <guid>https://dev.to/saucekode/automate-ci-cd-build-pipeline-for-a-springboot-app-using-jenkins-and-github-webhooks-3h30</guid>
      <description>&lt;p&gt;In this article, you will be learning how to set up a CI/CD pipeline for your springboot application using Jenkins and Github webhooks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A working knowledge of Springboot&lt;/li&gt;
&lt;li&gt;Jenkins installed on your machine&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Continous integration and delivery make up the devops lifecycle. There are 8 phases in the devops lifecyle. &lt;/p&gt;

&lt;p&gt;Continous delivery make up the first four phases which include: &lt;strong&gt;plan, code, build and test&lt;/strong&gt;. Continous integration make up the last four phases which include: &lt;strong&gt;integrate, deploy, operate and monitor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Jenkins is a tool for integrating automatically into the existing codebase after testing is complete. It spans both continous delivery (build and test phase) and continous integration (integration).&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a repository and branches
&lt;/h3&gt;

&lt;p&gt;If your project is already hosted on Github, you can skip this step. Otherwise, create a repository on Github, map the remote url to your project and create two branches: &lt;strong&gt;prod&lt;/strong&gt; and &lt;strong&gt;dev&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The dev branch is what Jenkins will be interfacing with, once there is a successful build in this branch then we can integrate the changes into our prod branch, this would interface with your deployment platform.&lt;/p&gt;

&lt;p&gt;Using this method, we will catch errors during development and avoid them at production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Setup Jenkins server
&lt;/h3&gt;

&lt;p&gt;To start up Jenkins for Ubuntu users, locate the &lt;em&gt;jenkins.war&lt;/em&gt;  file in the /usr/share/jenkins path. Once found, run the command below to start Jenkins manually.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -jar jenkins.war --httpPort=8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;For Windows and MacOs users, &lt;a href="https://www.jenkins.io/doc/book/installing/" rel="noopener noreferrer"&gt;view&lt;/a&gt; the official Jenkins documentation for how to setup the server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You should have Jenkins running now. Jenkins default port is 8080. Head over to your browser and run &lt;strong&gt;localhost:8080&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;An aside, Springboot runs on port 8080 as well, you will have to change your port using &lt;strong&gt;server.port=9090&lt;/strong&gt; in your &lt;em&gt;application.properties&lt;/em&gt; file.&lt;/p&gt;

&lt;p&gt;If you're using Jenkins for the first time, you will be presented with a page that has path to a file. The file contains your Jenkins administrator password. Copy the path. To view the contents, run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat &amp;lt;file path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that is done, you should be able to see the password. Copy and paste into the input field provided and click the button. Next up, you will be required to install Jenkins plugins. You can choose to install all plugins or install selected plugins. Go for the former and wait for the installation to be done. If it fails, retry. &lt;/p&gt;

&lt;p&gt;After the installation is complete. You will be required to create a new user admin. You can choose to skip this step and continue with the initial administrator credentials provided by Jenkins. I strongly advise you create a new user. Once that is done, you will be redirected to your Jenkins dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Set up Jenkins credentials
&lt;/h2&gt;

&lt;p&gt;This step is vital in the build automation. On the dashboard menu items, click &lt;strong&gt;Manage Jenkins&lt;/strong&gt; and then, &lt;strong&gt;Manage Credentials&lt;/strong&gt;. There is an already existing Jenkins credential. Click on it and then the Global credentials. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbcbyp2r53yq83sphk76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbcbyp2r53yq83sphk76.png" alt="add jenkins credentials"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Add Credentials&lt;/strong&gt; and you will be presented with where to fill your details.&lt;/p&gt;

&lt;p&gt;Github no longer has support for username and password. In selecting a credential kind, pick SSH Username with private key. This means you should already have your SSH keys (private and public). &lt;/p&gt;

&lt;p&gt;If you do not have one, follow this link to generate yours and link to Github &lt;a href="https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enter your username and select &lt;strong&gt;Enter directly&lt;/strong&gt; in the private key option and make sure it is your generated private SSH key you are entering not the public SSH key. Click OK to continue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Set up Jenkins pipeline
&lt;/h2&gt;

&lt;p&gt;Go back to your dashboard. Create a job. Enter a name for your job, select Freestyle project and save to continue.&lt;/p&gt;

&lt;p&gt;Enter a description for your Jenkins job in the General tab. In the source code management tab, select Git, enter the repository url for your project. Under credentials, select the credential your created. In branches to build, edit the prepopulated branch and set to dev. &lt;/p&gt;

&lt;p&gt;In the Build Triggers tab, check &lt;strong&gt;GitHub hook trigger for GITScm polling&lt;/strong&gt;. You can choose to run this trigger with the &lt;strong&gt;Poll SCM&lt;/strong&gt; option. This setup would require you input a time schedule for when the hook trigger would happen. Currently, I didn't select the Poll SCM option.&lt;/p&gt;

&lt;p&gt;Scroll to the Build tab and select &lt;strong&gt;Execute shell&lt;/strong&gt;. This is where we specify the build command for our Spring application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./mvnw install test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Input this maven build command, it runs both test and build our app into an artifact. Once done, click save.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Setup Github WebHook
&lt;/h2&gt;

&lt;p&gt;The webhook automates the build process as opposed to manually running the build from Jenkins.&lt;/p&gt;

&lt;p&gt;Navigate to the settings tab of your spring app github repository, click on &lt;strong&gt;Webhooks&lt;/strong&gt;. You will be required to provide a &lt;strong&gt;Payload URL&lt;/strong&gt; and &lt;strong&gt;secret&lt;/strong&gt;. The secret key is a token you generate in Jenkins and it is used to make API calls. For our payload URL, we will generate one using ngrok. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ngrok is a tool for generating a live URL for your locally hosted project. We need to expose Jenkins to our webhook, hence the need for ngrok.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Download ngrok zip file from &lt;a href="https://ngrok.com/download" rel="noopener noreferrer"&gt;here&lt;/a&gt; and unzip. Open your terminal and cd into the directory you unzipped ngrok.&lt;/p&gt;

&lt;p&gt;For Ubuntu users, run this command to generate a url:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./ngrok http 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to append &lt;strong&gt;/github-webhook/&lt;/strong&gt; to your payload url, this is required by the webhook. Set content type to &lt;strong&gt;application/json&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's get our secret token. In your Jenkins dashboard, click on the dropdown arrow beside your name located at the top left corner. Select &lt;strong&gt;configure&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1iri89ajhznc99e2bmy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1iri89ajhznc99e2bmy.png" alt="jenkins api token"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll down to locate the API token tab, click on &lt;strong&gt;Add new token&lt;/strong&gt; and generate one. Once it is generated, copy the token, save and paste it in the secret field in github.&lt;/p&gt;

&lt;p&gt;In github, still in webhooks, the question &lt;strong&gt;Which events would you like to trigger this webhook?&lt;/strong&gt;, for this article we will select &lt;strong&gt;Just the push event&lt;/strong&gt; option and click &lt;strong&gt;Add webhook&lt;/strong&gt;. You can explore other options to see what they offer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Test CI/CD pipeline
&lt;/h2&gt;

&lt;p&gt;You should be in your dev branch. Make changes to your code and push. The build started automatically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ts0bhjne2pm0wllgosh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ts0bhjne2pm0wllgosh.png" alt="jenkins buils"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the build is successful, next, make a merge request to the prod branch and deploy.&lt;/p&gt;

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

&lt;p&gt;In this article, we successfully setup a CI/CD pipeline using Jenkins and with Github webhooks, automated our build process as opposed to manually triggering the build from Jenkins.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>beginners</category>
      <category>jenkins</category>
    </item>
    <item>
      <title>How to deploy a web app using AWS and Nginx</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Tue, 14 Sep 2021 19:06:43 +0000</pubDate>
      <link>https://dev.to/saucekode/how-to-deploy-a-web-app-using-aws-and-nginx-51ij</link>
      <guid>https://dev.to/saucekode/how-to-deploy-a-web-app-using-aws-and-nginx-51ij</guid>
      <description>&lt;p&gt;In this tutorial, we wil be learning how to deploy a simple web application to the cloud using AWS and Nginx.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A web application you want to deploy&lt;/li&gt;
&lt;li&gt;An AWS account&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Select a region
&lt;/h2&gt;

&lt;p&gt;Regions are very important in deploying your application to the cloud. Why? The closest the region is to the user, the faster they can access resources from the server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1q10w88n2r0q4c02sv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1q10w88n2r0q4c02sv3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above, I selected North Virginia as my server region, and you are free to choose a different one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create an instance
&lt;/h2&gt;

&lt;p&gt;First step, we need to set up the instance where we would be deploying our application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An instance in layman term is a remote computer or as written in the AWS docs - a virtual computing environment. Instance is the term given to a remote machine by AWS, other cloud service providers like Digitalocean and Microsoft's Azure simply call theirs Droplets and Virtual Machines respectively.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Log into your AWS console as a root user. Navigate to the AWS services card and select EC2 (Elastic Compute Cloud) service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foyxaje5wdnnogx6jf9qk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foyxaje5wdnnogx6jf9qk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be presented with this page. Click on &lt;strong&gt;Launch instances&lt;/strong&gt;. You will be required to choose an Amazon Machine Image. A machine image represents the type of OS your virtual computer would run on, because, what's a computer without an OS?&lt;/p&gt;

&lt;p&gt;I selected the Ubuntu Server 20.04 LTS (HVM), SSD Volume Type, you are free to choose a different image. &lt;/p&gt;

&lt;p&gt;Next up, select an instance type needed to run your application. Instance types are more like CPU capacity and processor type for your machine.&lt;/p&gt;

&lt;p&gt;Here, I picked the t2.micro instance type. It's on the free tier plan. You can choose a different instance type, depending on what your application demands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4hhvbw9pufn736qq2t5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4hhvbw9pufn736qq2t5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next up, we configure the details for our instance.&lt;/p&gt;

&lt;p&gt;Here, we are going to edit two things. Our subnet information and user data. The idea behind user data is to preinstall softwares you will be needing in your virtual machine. &lt;/p&gt;

&lt;p&gt;Select any subnet for your machine, after this is done, an IP address is assigned to your VM. IP addresses are ways to identify a computer, communicate and share resources with them. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgkhkj1itds55ww707k3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgkhkj1itds55ww707k3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is an option to create your own subnet and if you decide to make your newly created subnet private, you cannot be able to access resources provided to public subnets in that region. Simply, AWS provides every instance internet to pull resources. If you make your subnet private, you will have to find a way to pull resources.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2lrxweo7ui09cev39uc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2lrxweo7ui09cev39uc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the userdata, I specified that I want git preinstalled into my vm.&lt;/p&gt;

&lt;p&gt;Next, set up storage for your vm. This is more like your SSD. Remember my machine image is of SSD volume type.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzpc5j5zaall7lmm2vea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzpc5j5zaall7lmm2vea.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, tags. Leave your tags empty. Tags are more like labels you give to your AWS resources. It is presented as a key-value pair data structure.&lt;/p&gt;

&lt;p&gt;Next, security groups. There is a default security group set for your instance. Security groups are more like firewalls. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Firewalls are protective walls for what type of requests come into our server. For example: you can block HTTP requests from accessing your web application&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can choose to use an existing security group or create a new one. I will be creating a new one. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fczu6ayaexl4kh098ehu4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fczu6ayaexl4kh098ehu4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, review everything and launch.&lt;/p&gt;

&lt;p&gt;After launch, you will be required to create a key pair either RSA or ED25519 format. This is required to securely log into your ec2 instance shell. Select a pair type and give it a name. Download the key pair. Once done, launch your instance.&lt;/p&gt;

&lt;p&gt;After this, your instance should be up and running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0yxiid7bn2n2finksjc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0yxiid7bn2n2finksjc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Log into your virtual machine
&lt;/h2&gt;

&lt;p&gt;Our remote machine is ready for deployment but we need to login and perform the deployment operation. The way you have a physical machine and log into with a username and password. We are dealing with a remote machine and so we need a way to connect to it, the key pair you created and downloaded is the way to connect.&lt;/p&gt;

&lt;p&gt;Click on your instance ID and click connect. Copy the highlighted command (I highlightd it, not AWS) using the copy icon situated left of the command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fia40b5szu8iq62wtxhg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fia40b5szu8iq62wtxhg1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open your terminal. If you are using a Windows machine, download git bash or WSL (Windows subsystem for Linux). If you are using a Linux machine, don't bother. Now, cd into the directory where you downloaded that ssh key pair, paste the command you copied and press enter to run it.&lt;/p&gt;

&lt;p&gt;Follow the prompt. If you get the error in the image below, don't worry, simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 400 &amp;lt;name of RSA file&amp;gt;.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqaxncjdk5b5bf0db5k4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqaxncjdk5b5bf0db5k4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once done, run the ssh command again and now you should be logged into your vm. Yippie! 😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsmm2i9rwmgavt8s1b4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsmm2i9rwmgavt8s1b4w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, git was successfully installed. Remember what we specified in our user data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Set up Nginx server
&lt;/h2&gt;

&lt;p&gt;Before we set up the Nginx server, we have to install Nginx.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NGINX is an open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more - &lt;a href="http://www.nginx.com" rel="noopener noreferrer"&gt;www.nginx.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Generally in Linux, there are operations that require administrator rights so you would need the &lt;strong&gt;sudo&lt;/strong&gt; command. We can choose to eliminate that and carry out those operations without admin rights by running the &lt;strong&gt;sudo su&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;Download the nginx signing key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget http://nginx.org/keys/nginx_signing.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the downloaded key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-key add nginx_signing.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbkzzwk5qmy5fzn37rfd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbkzzwk5qmy5fzn37rfd.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should be the response.&lt;/p&gt;

&lt;p&gt;cd into the /etc/apt directory and edit the sources.list file by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano sources.list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once your nano editor is open, add this to the end of the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deb http://nginx.org/packages/ubuntu xenial nginx
deb-src http://nginx.org/packages/ubuntu xenial nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return to home directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /home/ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the apt-get update command to update the Nginx software.&lt;/p&gt;

&lt;p&gt;Once the update is complete, install Nginx. Run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-get install nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have issues installing nginx. If this error comes up, demanding you install libssl1.0.0 dependency.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fparp1ihu4n5fzeuosyt7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fparp1ihu4n5fzeuosyt7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run this command sequentially.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "deb http://security.ubuntu.com/ubuntu bionic-security main" | sudo tee -a /etc/apt/sources.list.d/bionic.list

sudo apt update

apt-cache policy libssl1.0-dev

sudo apt-get install libssl1.0-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run again to install nginx,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-get install nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the nginx service. Run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;service nginx start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To ensure the nginx service is up and running. Run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl status nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's run our instance over the browser, if the default nginx page is served, then it works perfectly.&lt;/p&gt;

&lt;p&gt;Right now, our web page will not be served, you will notice the browser loading without an information. We missed one vital step. The protocol for web browsers to fetch web pages is HTTP. When we set up our security groups, we had only one rule which is the SSH rule. We need to edit our security group to add in the HTTP rule.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vqnjmj7adakez1mcec7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vqnjmj7adakez1mcec7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the security groups. Click on &lt;strong&gt;Edit inbound rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50xn5la2egm5sicexm2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50xn5la2egm5sicexm2h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;Add rule&lt;/strong&gt;. Select HTTP. Set CIDR blocks to 0.0.0.0/0 and click &lt;strong&gt;Save rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F86vbnol3ixlzp63u13af.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F86vbnol3ixlzp63u13af.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Restart the nginx server. Run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the instance over the browser again. Edit the protocol in the url from https to http.&lt;/p&gt;

&lt;p&gt;This is what we should have now. Yippie!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6s1418vhe8dmztjvohi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6s1418vhe8dmztjvohi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Deploying our web app
&lt;/h2&gt;

&lt;p&gt;I will be deploying a react app.&lt;/p&gt;

&lt;p&gt;First, we need to install nodejs. A react application cannot function without nodejs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt update
apt install nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm node and npm is intalled&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
npm -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If node is installed but npm is not, simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-get install npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, clone your react project from github.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone &amp;lt;project repository on github&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, navigate into the project directory, install the dependencies and build the react project. Run these commands respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, copy the contents of your build to the html directory in nginx.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp -r /home/ubuntu/&amp;lt;directory name&amp;gt;/build/. /usr/share/nginx/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, restart your nginx service and run your instance over the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F574f70fxkj0hi59i3u49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F574f70fxkj0hi59i3u49.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You've successfully deployed a web app to AWS.&lt;/p&gt;

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

&lt;p&gt;This article taught us how seamless it is to deploy a web application using AWS and Nginx. Head over to the &lt;a href="https://docs.aws.amazon.com/index.html" rel="noopener noreferrer"&gt;AWS docs&lt;/a&gt; for more tutorials on using AWS services.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>learning</category>
      <category>nginx</category>
      <category>devops</category>
    </item>
    <item>
      <title>Understanding vue by building a country directory app part 3</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Fri, 17 Jul 2020 23:01:45 +0000</pubDate>
      <link>https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-3-jf</link>
      <guid>https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-3-jf</guid>
      <description>&lt;p&gt;Hello everyone, we'll be continuing on our article episode. I know I said I was going to post this yesterday but I couldn't because I was down with a cold, I apologize and I feel a lot better now. I'm sitting at my desk right now and excited to churn this out 🙂&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Objective&lt;/strong&gt;&lt;br&gt;
By the end of this post, you should: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a good understanding of props and how the parent component communicates with the child component and vice-versa.&lt;/li&gt;
&lt;li&gt;Add dark mode theme to our app&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's establish a foundation before we gradually build up. The feature we are about to add is made possible with props, so let me introduce it briefly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is props?&lt;/strong&gt;&lt;br&gt;
Props simply means properties. It is data that is been passed from the parent or root component to the child. Props can be a string, function, array, boolean or object; it's basically primitive data type. It cannot be changed in a child component only where it was first declared which is the parent component. Vue refers to this act as prop mutation when you try to set it to a new value in a child component.&lt;/p&gt;

&lt;p&gt;Let's move on.&lt;/p&gt;

&lt;p&gt;Remember I said props are data passed from parent to child component. First, our data has to be declared in a parent component. Now, we'll head over to our &lt;strong&gt;App.vue&lt;/strong&gt; file and declare our data and we do that in reserved Vue property known as the data property, the name even tells what it does. In the parent component, it is data but in a child component, it is props. Hope that made sense?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Root component (App.vue)&lt;/strong&gt;&lt;br&gt;
In the data property, we are going to set three data states: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;modeTheme&lt;/li&gt;
&lt;li&gt;modeIcon&lt;/li&gt;
&lt;li&gt;modeText&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The modeTheme would affect the color state of our app, at first we will be setting it to 'light' which is the default color state.&lt;/p&gt;

&lt;p&gt;The modeIcon and modeText would only affect the Toggle component. At first the modeIcon will be set to 'fa fa-moon-o' and the modeText set to 'dark'. Both are default states as seen in our app. Armed with some JavaScript logic, we will change these states.&lt;/p&gt;

&lt;p&gt;This is what we should have now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default {
  name: "App",
  data(){
    return{
      modeTheme: 'light',
      modeIcon: 'fa fa-moon-o',
      modeText: 'dark'
    }
  },
  components: {
    Header,
    Content
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's begin building our app Vue Style. Next thing is we are going to bind our data to the child components. In binding data as props to a child, the prop should of course have a name and the data it is pointing to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header and Toggle component&lt;/strong&gt;&lt;br&gt;
First, we will take out 'dark mode' and 'fa fa-moon-o' we hard coded in the Toggle component. The prop names &lt;strong&gt;iconMode&lt;/strong&gt; and &lt;strong&gt;textMode&lt;/strong&gt; bind to the &lt;strong&gt;modeIcon&lt;/strong&gt; and &lt;strong&gt;modeText&lt;/strong&gt; data respectively. We add them into our header component tag using either &lt;strong&gt;v-bind&lt;/strong&gt; attribute or its shortcut :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Header 
  :iconMode="modeIcon"
  :textMode="modeText"
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know you're thinking, how does this even relate? If you go back to part 1 we imported the Toggle component into the Header, this made Toggle a child to Header. Toggle has an indirect access to the data in root component (App.vue) through it's own parent (Header.vue) and this is made possible through props.&lt;/p&gt;

&lt;p&gt;We will quickly add in our props into the header vue instance and there is a reserved property name for it known as props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default{
    import Toggle from './Toggle'
    name: 'Header',
    props: ["iconMode", "textMode"],
    components:{
      Toggle
    }
}

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

&lt;/div&gt;



&lt;p&gt;Our initial data in App.vue is binded to these prop names so don't be confused if you see &lt;strong&gt;iconMode&lt;/strong&gt; instead of &lt;strong&gt;modeIcon&lt;/strong&gt;, you can use either one but I prefer to use this. Now, at this point, Toggle has access to the &lt;strong&gt;modeIcon&lt;/strong&gt; and &lt;strong&gt;modeText&lt;/strong&gt; data. What we'll do next is, bind these props data to the Toggle tag component and declare them in the Toggle.vue file in reserved props property as we did for the Header.&lt;/p&gt;

&lt;p&gt;First, bind the props data to Toggle component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Toggle
   :toggleIcon="iconMode"
   :toggleTheme="textMode"
 /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, declare these prop names in the props property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default{
    name: 'Toggle',
    props: ["toggleIcon", 'toggleTheme']
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next up, use the prop names where needed. In this case we will be replacing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;i class="fa fa-moon-o"&amp;gt;&amp;lt;/i&amp;gt;
&amp;lt;span&amp;gt;Dark Mode&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with this, making our application reactive. Reactive in the sense that, if the data in &lt;strong&gt;toggleIcon&lt;/strong&gt; which points to &lt;strong&gt;modeIcon&lt;/strong&gt; in our App.vue does change, it would change here too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;i :class="toggleIcon"&amp;gt;&amp;lt;/i&amp;gt;
&amp;lt;span&amp;gt;{{toggleTheme}}&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we just binded our prop data to our class attribute since the data should be a class name and replaced the hard coded text with the data &lt;strong&gt;toggleTheme&lt;/strong&gt; using string interpolation. &lt;/p&gt;

&lt;p&gt;For my class bind, this is an expanded version of what I did up there. Choose whatever you like but the former is shorter BTW.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;i v-bind:class="toggleIcon"&amp;gt;&amp;lt;/i&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm taking my time to explain it so I don't get to explain again and again. Hopefully all I've said so far made sense.&lt;/p&gt;

&lt;p&gt;Moving on...&lt;/p&gt;

&lt;p&gt;It's time to work on our color state. Back in our root component, the default color (here I mean both background and text color) state was set to 'light' but we want to be able to change the state from light to dark and vice-versa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How will we make this happen?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We will add a click event to our Toggle component and assign a custom event through an &lt;strong&gt;$emit&lt;/strong&gt;. The &lt;strong&gt;$emit&lt;/strong&gt; is a way to pass data from child component to parent component through custom events.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's do that now:&lt;/p&gt;

&lt;p&gt;In our Toggle component, add a click event handler together with an &lt;strong&gt;$emit&lt;/strong&gt; which will point to a &lt;strong&gt;toggle&lt;/strong&gt; string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Toggle" @click="$emit('toggle')"&amp;gt;
    &amp;lt;button&amp;gt;
     &amp;lt;i :class="toggleIcon"&amp;gt;&amp;lt;/i&amp;gt;
     &amp;lt;span&amp;gt;{{toggleTheme}}&amp;lt;/span&amp;gt;
    &amp;lt;/button&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I'm signalling to the parent component (Header) that there is an incoming custom event 'toggle'. &lt;/p&gt;

&lt;p&gt;In the Header component where the Toggle component tag is declared, I will bind the custom event 'toggle' to another custom event called 'toggler' using &lt;strong&gt;$emit&lt;/strong&gt;, but we are not done yet, our root component isn't still aware of the click event happening in our Toggle. Remember, we pass data from child to parent through &lt;strong&gt;$emit&lt;/strong&gt;. We successfully made that happen from Toggle to Header, now we need to do same from Header to App.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Header"&amp;gt;
    &amp;lt;h2&amp;gt;Where in the world?&amp;lt;/h2&amp;gt;
    &amp;lt;Toggle
      :toggleIcon="iconMode"
      :toggleTheme="textMode"
      :toggle="$emit('toggler')"
    /&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now 'toggler' would do the final work of signalling the root component of the existence of a click event. It will be the custom event the root component works with. It will be declared in the fashion of all event handlers, either like this v-on:toggler or @toggler. At this point, it represents the @click event handler, which I must say is a very interesting twist.&lt;/p&gt;

&lt;p&gt;In the Header tag component, we will alert the root component that there is a custom event representing a click event and that it carries a function called &lt;strong&gt;toggleIt&lt;/strong&gt; as seen in the code block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    &amp;lt;Header 
      :iconMode="modeIcon"
      :textMode="modeText"
      @toggler="toggleIt"
    /&amp;gt;
    &amp;lt;Content/&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With our &lt;strong&gt;toggleIt&lt;/strong&gt; function announced to the root component, we declare it inside our &lt;strong&gt;methods&lt;/strong&gt; property, another reserved space for storing functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What should the toggleIt function do?&lt;/strong&gt;&lt;br&gt;
This is basically where we write our JavaScript logic to control color state. Let's do that now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;methods:{
    toggleIt(){
      if(this.modeTheme === 'light'){
        this.modeTheme = 'dark';
        this.modeIcon = 'fa fa-sun-o';
        this.modeText = 'light mode'
      }else{
        this.modeTheme = 'light';
        this.modeIcon = 'fa fa-moon-o';
        this.modeText = 'dark mode'
      }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I believe whoever is reading this post has a vanilla JS  background and so no need to go over this. You shouldn't be getting into Vue without knowledge of Vanilla.&lt;/p&gt;

&lt;p&gt;Now, one final thing to achieve our aim. We need to pass the data &lt;strong&gt;modeTheme&lt;/strong&gt; from parent (App) to the children components by binding it through props. From our logic above, we are changing the state of &lt;strong&gt;modeTheme&lt;/strong&gt; based on it's current state. So, if it's dark when I clicked, set it to light and vice-versa.&lt;/p&gt;

&lt;p&gt;We need some way to show the state switching does work. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt;&lt;br&gt;
Bind &lt;strong&gt;themeMode&lt;/strong&gt; which is the name of the prop pointing to the initial data &lt;strong&gt;modeTheme&lt;/strong&gt; in App to a class using the v-bind directive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Header" :class="themeMode"&amp;gt;
    &amp;lt;h2&amp;gt;Where in the world?&amp;lt;/h2&amp;gt;
    &amp;lt;Toggle
      :toggleIcon="iconMode"
      :toggleTheme="textMode"
      v-on:toggle="$emit('toggler')"
    /&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
  import Toggle from './Toggle'
  export default{
    name: 'Header',
    props: ["iconMode", "textMode", "themeMode"],
    components:{
      Toggle
    }
  }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final result for Header and so since the &lt;strong&gt;themeMode&lt;/strong&gt; prop is being binded to a class, there should be an actual class name declared in our style, this is so when my state goes from 'light' to 'dark', my 'dark' state which is a css class should kick in. This is even cooler because, we get to pass this &lt;strong&gt;themeMode&lt;/strong&gt; prop across different components and decide what type of color we want for our 'dark' state.&lt;/p&gt;

&lt;p&gt;Guys, this has been a long one. I'm glad I finally came to the end of it. This is me documenting my learning process and frankly, before I started writing, I didn't understand the whole $emit thing but right now, I can boldly say, it all makes sense now.&lt;/p&gt;

&lt;p&gt;If it made sense to you. Do comment below and suggestions are welcome. Thank you. Next up would be populating our app with country data, that won't be tomorrow but my next post.&lt;/p&gt;

&lt;p&gt;Link to code: &lt;a href="https://codesandbox.io/s/country-directory-app-4byey?file=/src/App.vue"&gt;https://codesandbox.io/s/country-directory-app-4byey?file=/src/App.vue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Link to demo: &lt;a href="https://4byey.codesandbox.io/"&gt;https://4byey.codesandbox.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stay safe and byee!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Vue by building a country directory app Part 2</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Wed, 15 Jul 2020 14:31:38 +0000</pubDate>
      <link>https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-2-1oe6</link>
      <guid>https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-2-1oe6</guid>
      <description>&lt;p&gt;Hello everyone! I'm so excited on the next stage of our app, we're making progress already. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Objective&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add in our search, filter and countries components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start by creating new components Search.vue, Filter.vue and Countries.vue&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search component&lt;/strong&gt;&lt;br&gt;
This component would have our search input where we look for different countries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
    &amp;lt;div class="Search"&amp;gt;
        &amp;lt;input type="search" placeholder="Search for a country..."&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
    export default{
        name: 'Search'
    }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
    .Search input[type="search"]{
        width: 350px;
        height: 45px;
        background: #fff;
        padding: 2px 18px 0 0;
        border-radius: 4px;
        text-indent: 18px;
        box-shadow: 0 0 10px rgba(0,0,0,0.3);
        font-weight: 600;
    }

    .Search input[type="search"]::placeholder{
        font-family: 'Nunito Sans';
        font-weight: 600;
        color: #192734;
    }

&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Filter component&lt;/strong&gt;&lt;br&gt;
This component has a select tag and would basically filter out countries based on regions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
    &amp;lt;div class="Filter cursor-point"&amp;gt;
        &amp;lt;select id="Filter-Select"&amp;gt;
            &amp;lt;option value="default"&amp;gt;Filter by region&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
    export default{
        name: 'Filtersearch'
    }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
    .Filter #Filter-Select{
        width: 180px;
        height: 45px;
        background: #fff;
        border-radius: 4px;
        text-indent: 15px;
        box-shadow: 0 0 10px rgba(0,0,0,0.3);
        font-weight: 600;
        color: #192734;
    }

    .dark #Filter-Select{
        background: hsl(209, 23%, 22%);
        color: #fff
    }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, after successfully creating our search and filtersearch components, we import them into the &lt;strong&gt;Content.vue&lt;/strong&gt; component.&lt;/p&gt;

&lt;p&gt;The next component we would be creating is the &lt;strong&gt;countries&lt;/strong&gt; component. It would hold all our individual countries as seen in the design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Countries component&lt;/strong&gt;&lt;br&gt;
This component is going to be a container for all our countries. Remember, the talk about components in part 1? Each country is represented with the Country component and will be reused in this particular component. I haven't set up the design for the Country component but will do that when we begin making HTTP requests to the API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Countries"&amp;gt;

  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
 export default{
   name: 'Countries'
 }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
  .Countries{
    background: dodgerblue;
    padding: 25px;
    margin-top: 25px;
  }
&amp;lt;/style&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;I'm using the nice blue color to let you know the component does exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Content component should look like&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Content"&amp;gt;
    &amp;lt;div class="Content-sf"&amp;gt;
      &amp;lt;Search/&amp;gt;
      &amp;lt;Filtersearch/&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;Countries/&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
  import Search from './Search';
  import Filtersearch from './Filter';
  import Countries from './Countries';
  export default{
    name: 'Content',
    components:{
      Search,
      Filtersearch,
      Countries
    }
  }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
  .Content{
    padding: 25px 30px;
    background: #f5f5f5;
    height: 88vh;
  }

  .Content-sf{
    display: flex;
    justify-content: space-between;
  }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That will be all for this section. I'm super excited about tomorrow's episode. We would be adding some pop to our app -- ta-da! &lt;strong&gt;DARK MODE THEME&lt;/strong&gt; 😏😏&lt;/p&gt;

&lt;p&gt;You can vue (pun intended, lol!) the app here: &lt;a href="https://12oqz.csb.app/"&gt;https://12oqz.csb.app/&lt;/a&gt;&lt;br&gt;
See you later, byeee!!!🙂 &lt;/p&gt;

&lt;p&gt;If you missed part one, here it is: &lt;a href="https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-1-2n9"&gt;https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-1-2n9&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Vue by building a country directory app Part 1</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Tue, 14 Jul 2020 20:26:39 +0000</pubDate>
      <link>https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-1-2n9</link>
      <guid>https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-1-2n9</guid>
      <description>&lt;p&gt;Hello everyone. This is my very first article on VueJs. I've been learning Vue for a while now and honestly it has been a bitter-sweet experience for me. I hear people say Vue is easy, yea, it is indeed easy because you feel at home, it's still HTML but with some nice perks and those &lt;strong&gt;perks&lt;/strong&gt; was the bitter part but it's a process so I'm getting there. In this series, all I will be doing is just documenting my learning experience. &lt;/p&gt;

&lt;p&gt;On today's episode I will building a full fledged application with a dark mode theme and this is to be sure I really did understand the tutorial I have been on. It's a challenge for me and I'm taking it. This particular article would be in parts because I don't want it so long. I'll just break them into small pieces.&lt;/p&gt;

&lt;p&gt;What our final application should look like after we're done:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7aLs6DUy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6118z3u7s6ayb48ky0ip.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7aLs6DUy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6118z3u7s6ayb48ky0ip.jpg" alt="image contains countries"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I am a big believer in writing the actual code than just binge-watching tutorials and not doing anything about them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I will be building this on codesandbox, of course, you can do this in your IDE after creating a new project in Vue. This tutorial isn't really about how to get started with Vue so I won't be talking about that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick Breakdown&lt;/strong&gt;&lt;br&gt;
Our app is going to be made up of basically six components which I'll talk about as I progress. They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Header&lt;/li&gt;
&lt;li&gt;Toggle&lt;/li&gt;
&lt;li&gt;Search&lt;/li&gt;
&lt;li&gt;Filter&lt;/li&gt;
&lt;li&gt;Countries&lt;/li&gt;
&lt;li&gt;Country&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Project Structure&lt;/strong&gt;&lt;br&gt;
The image below describes what my file structure looks like. Just create the different files. I'm currently building with Codesandbox, it gives the IDE experience but online. I took out the assets folder since we won't be needing it in this tutorial. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--InHVkYed--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ov2ksfpym1xj4pae4v0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--InHVkYed--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ov2ksfpym1xj4pae4v0m.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll be using the Nunito font, you can copy this link right here and paste in your index.html file, it's found in your &lt;strong&gt;public&lt;/strong&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link href="https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@300;600;800&amp;amp;display=swap" rel="stylesheet"&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Let's begin building out our different components.&lt;/p&gt;

&lt;p&gt;A quick one before I dive in. I'll just do a layman explanation of what a component is for my friends who hail from Vanilla JS.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A component is a small, reusable part of an application whether big or small. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before the advent of frameworks like Vue and the rest, we wrote lots of beautiful HTML for large applications which I must confess can go from mildly confusing to seriously annoying. Why write 50,000 lines of code when you can break them into small pieces and bring them all together into one root element which now represents the whole app? Hopefully, that made sense. &lt;/p&gt;

&lt;p&gt;So now, let's dive right in!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header Component&lt;/strong&gt;&lt;br&gt;
This component represents our header. It will be holding one component which in this case is the Toggle component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Header"&amp;gt;
    &amp;lt;h2&amp;gt;Where in the world?&amp;lt;/h2&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
  export default{
    name: 'Header'
  }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;

  .Header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 25px;
    background: #ffffff;
    color: #192734;
    box-shadow: 0 0 5px rgba(0,0,0,0.4);
  }

&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding the styles, import the component into the root component which in this case is our &lt;strong&gt;App.vue&lt;/strong&gt; file. Our app should come alive by now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content Component&lt;/strong&gt;&lt;br&gt;
This component would have three components (country, search and filtersearch) which will be referenced in our components property. Components property is a vue feature that allows a component keep track of all components imported into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div class="Content"&amp;gt;
    &amp;lt;!-- Country component --&amp;gt;
    &amp;lt;!-- Search component --&amp;gt;
    &amp;lt;!-- Filtersearch component --&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
  export default{
    name: 'Content'
  }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
  .Content{
    padding: 25px 30px;
    background: #f5f5f5;
    height: 88vh;
  }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Toggle Component&lt;/strong&gt;&lt;br&gt;
This component is responsible for the toggle action between dark and light theme when we implement our dark mode feature. &lt;/p&gt;

&lt;p&gt;I will be using Font Awesome for my icons, use whatever font icon you love.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;template&amp;gt;
  &amp;lt;div class="Toggle"&amp;gt;
    &amp;lt;button&amp;gt;
     &amp;lt;i class="fa fa-moon-o"&amp;gt;&amp;lt;/i&amp;gt;
     &amp;lt;span&amp;gt;Dark Mode&amp;lt;/span&amp;gt;
    &amp;lt;/button&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
  export default{
    name: 'Toggle'
  }
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
  .Toggle{
    color: #197432;
  }

  button{
    background: none;
    outline: none;
    border: none;
  }

  button span{
    font-weight: 600;margin-left: 6px

  }

&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, import your Toggle component into your Header component and you'll be good.&lt;/p&gt;

&lt;p&gt;Now, this is what our root component (App.vue) should look like after importing our Header and Content components. You don't see the Toggle component here because it is a small piece attached to the Header component, in this case, it is a child of the Header component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    &amp;lt;Header/&amp;gt;
    &amp;lt;Content/&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import Header from './components/Header';
import Content from './components/Content';

export default {
  name: "App",
  components: {
    Header,
    Content
  }
};
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
*, *::before, *::after{
  margin: 0;
  padding:0;
  outline: none;
  border: none
}

#app{
  font-family: 'Nunito Sans', sans-serif;
  min-height: 100vh;
}
&amp;lt;/style&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;I'll stop here, then tomorrow, we'll move on to creating the rest of the components. This is what our app looks like: &lt;a href="https://12oqz.csb.app/"&gt;https://12oqz.csb.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be creative with yours, musn't look like mine. Till tomorrow. Byeee!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Learn React with me - Welcome to React</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Mon, 24 Feb 2020 14:05:16 +0000</pubDate>
      <link>https://dev.to/saucekode/learn-react-with-me-welcome-to-react-45e3</link>
      <guid>https://dev.to/saucekode/learn-react-with-me-welcome-to-react-45e3</guid>
      <description>&lt;p&gt;I heard the best way to learn anything is to teach it and you get to master it. I just began learning React and I feel so late to the party. The only comfort I have is as I share my thoughts, others coming into the React world can navigate easily. Let's shoot!&lt;/p&gt;

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

&lt;p&gt;Simply put, React is a Javascript library that is used to create user interfaces.&lt;/p&gt;

&lt;p&gt;At first, I didn't get the whole fuss about React because I could just do the exact same thing with HTML, CSS and Javascript. Yes, I could build with these three comfortably but then I didn't know React existed to make my developer life easy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why should you even learn React?
&lt;/h2&gt;

&lt;h2&gt;
  
  
  React is fast.
&lt;/h2&gt;

&lt;p&gt;Like super fast. It gives users mobile app experience on the web. Click on a button that leads to another page, it just goes to said page in split seconds. It runs on the browser and has nothing to do with a server where you would need to wait for a response except in the cases of API calls.&lt;/p&gt;

&lt;h2&gt;
  
  
  React is component based.
&lt;/h2&gt;

&lt;p&gt;Now picture this, you're building a food directory website with just HTML and you wrote about 50,000 lines of code for just this one website. You run the code on the browser and boom! You see something shifted. Remember this webpage is made up of 50,000 lines of code. Now, you have to locate that bug. React makes this super easy. It is all about creating custom HTML elements.&lt;/p&gt;

&lt;p&gt;Look at it this way, every webpage is made up of components or parts. A simple webpage is made up of a header, sidebar and article sections. Since React is component based, you can easily create a header component that only contains header HTML. Sidebar component that contains only sidebar HTML and article component that contains article HTML.&lt;/p&gt;

&lt;p&gt;Now, when all these web pages have been put into components, it becomes easy to locate that bug if it is in any of these components and not have to scroll to find it. We'll learn about custom HTML elements as we go.&lt;/p&gt;

&lt;h2&gt;
  
  
  React keeps your code maintainable
&lt;/h2&gt;

&lt;p&gt;In normal HTML, it really is hard to write maintainable code, honestly. Do you know in React you actually write your Javascript inside your HTML? Normally, you would need to link a JS script to your HTML page and if it is a huge project, you would need to create multiple JS files for respective pages to avoid code conflicts. With React, you just write your JS inside your component and no need to link a script. So, it is easy to maintain the different parts of the page or files.&lt;/p&gt;

&lt;p&gt;There is so much more React actually does. Take these for now and go do further research.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why was React created?
&lt;/h2&gt;

&lt;p&gt;Let me use this simple illustration. Imagine a painter who of course paints. He paints a beautiful sky on his canvas for a very annoying client who keeps coming back to add new colors to the sky and for each new change, the painting is stressed except he would have to start all over again! I can only imagine. &lt;/p&gt;

&lt;p&gt;Let's bring it home, imagine a developer working for a client who comes back every two days to request an update on his webpage, if it's not color, it's the font or just simply add a new button to the sidebar. Now, just so you know, with each update you make to the DOM, the page load time gets slower. Not everyone has the patience for a slow website.&lt;/p&gt;

&lt;p&gt;Now enter React, it was created for an issue such as this. React presents to us what we know as a SHADOW DOM or VIRTUAL DOM. With each update to the web page, the DOM gets re-rendered and this makes what it spits to the page you see come slow. React becomes the middleman here. What React does, when you make an update, it renders what you have done on the VIRTUAL DOM (this is React's DOM) and only spits out the change to the main DOM hereby saving the DOM from re-rendering and what you get back is a faster page load. Cool right?&lt;/p&gt;

&lt;p&gt;I will leave this here for now for you to brood. Hope it inspires you to take a step to trying React out.&lt;/p&gt;

&lt;p&gt;Next time. Ciao.&lt;/p&gt;

</description>
      <category>react</category>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How reduce() function really works</title>
      <dc:creator>Chiamaka Mbah</dc:creator>
      <pubDate>Sun, 11 Aug 2019 23:01:30 +0000</pubDate>
      <link>https://dev.to/saucekode/how-reduce-function-really-works-3j6m</link>
      <guid>https://dev.to/saucekode/how-reduce-function-really-works-3j6m</guid>
      <description>&lt;h1&gt;
  
  
  Unveiling the Magic of JavaScript's reduce() Function
&lt;/h1&gt;

&lt;p&gt;Have you ever wondered how JavaScript's &lt;code&gt;reduce()&lt;/code&gt; function works its magic? Today, we're going to pull back the curtain and explore the inner workings of this powerful tool. By the end of this article, you'll not only know how to use &lt;code&gt;reduce()&lt;/code&gt;, but you'll also understand what's happening under the hood. Let's dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is reduce(), anyway?
&lt;/h2&gt;

&lt;p&gt;First things first: &lt;code&gt;reduce()&lt;/code&gt; is a higher-order function introduced in ES6 (ES2015). But what does that mean? Well, higher-order functions are like VIP functions – they get to hang out with other functions, taking them in as parameters or even returning them. Cool, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Superpower of reduce()
&lt;/h2&gt;

&lt;p&gt;So, what can &lt;code&gt;reduce()&lt;/code&gt; do for you? Imagine you have a basket full of apples, and you want to know how many you have in total. &lt;code&gt;reduce()&lt;/code&gt; is like your counting buddy, helping you turn that array of apples into a single number. It's not just for counting, though – &lt;code&gt;reduce()&lt;/code&gt; can help you combine array elements in all sorts of creative ways!&lt;/p&gt;

&lt;h2&gt;
  
  
  How reduce() Works: A Visual Guide
&lt;/h2&gt;

&lt;p&gt;Let's look at a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what's really going on here? Let's break it down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We start with an accumulator value of 0.&lt;/li&gt;
&lt;li&gt;For each number in our array, we add it to the accumulator.&lt;/li&gt;
&lt;li&gt;The accumulator keeps track of our running total.&lt;/li&gt;
&lt;li&gt;After we've gone through all the numbers, the accumulator gives us our final sum.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Peeking Under the Hood
&lt;/h2&gt;

&lt;p&gt;Now, let's see what &lt;code&gt;reduce()&lt;/code&gt; might look like if we wrote it ourselves:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myReduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;accumulator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;startIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;startIndex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;accumulator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function does the same job as the built-in &lt;code&gt;reduce()&lt;/code&gt;. Let's break it down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We set up our accumulator, either with the initial value or the first array element.&lt;/li&gt;
&lt;li&gt;We loop through the array, starting from the appropriate index.&lt;/li&gt;
&lt;li&gt;For each element, we call our callback function, updating the accumulator.&lt;/li&gt;
&lt;li&gt;Finally, we return the accumulator with our result.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  reduce() in Action: A Step-by-Step Breakdown
&lt;/h2&gt;

&lt;p&gt;Let's walk through our earlier example, step by step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start: accumulator = 0&lt;/li&gt;
&lt;li&gt;First round: 0 + 2 = 2 (accumulator is now 2)&lt;/li&gt;
&lt;li&gt;Second round: 2 + 3 = 5 (accumulator is now 5)&lt;/li&gt;
&lt;li&gt;Third round: 5 + 4 = 9 (accumulator is now 9)&lt;/li&gt;
&lt;li&gt;Fourth round: 9 + 5 = 14 (accumulator is now 14)&lt;/li&gt;
&lt;li&gt;Final round: 14 + 6 = 20 (accumulator is now 20)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And there you have it – 20 is our final result!&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Now you know the secret behind &lt;code&gt;reduce()&lt;/code&gt;'s power. It's not just about adding numbers – you can use this pattern to combine array elements in all sorts of creative ways. In our next post, we'll explore some real-world examples that go beyond simple arithmetic.&lt;/p&gt;

&lt;p&gt;Remember, understanding how &lt;code&gt;reduce()&lt;/code&gt; works under the hood isn't just about satisfying curiosity – it's about becoming a more informed and capable developer. So go forth and reduce with confidence!&lt;/p&gt;

&lt;p&gt;Happy coding! ❤️🚀💻&lt;/p&gt;

</description>
      <category>devjourney</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
