<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nuwanudara on Medium]]></title>
        <description><![CDATA[Stories by Nuwanudara on Medium]]></description>
        <link>https://medium.com/@nu1udara?source=rss-1a791f92e1b6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6ar_UcWbaZIsE_B7</url>
            <title>Stories by Nuwanudara on Medium</title>
            <link>https://medium.com/@nu1udara?source=rss-1a791f92e1b6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:10:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nu1udara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Get Started with Kubernetes and MicroK8s: A Beginner’s Guide to Container Orchestration]]></title>
            <link>https://medium.com/yaalalabs/get-started-with-kubernetes-and-microk8s-a-beginners-guide-to-container-orchestration-c40a1ed54c38?source=rss-1a791f92e1b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c40a1ed54c38</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microk8s]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Nuwanudara]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 05:10:00 GMT</pubDate>
            <atom:updated>2023-06-12T05:10:00.231Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>This is the first part of a series of posts that will introduce you to Kubernetes with the usage of MicroK8s. This is targeted at people getting started with Kubernetes.</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GrvG3VSZJ300bXmU.png" /><figcaption>Kubernetes (Source: <a href="https://1000logos.net/kubernetes-logo/">1000logos</a>)</figcaption></figure><h4><strong>What you need to know before jumping into Kubernetes.</strong></h4><p>Kubernetes is a powerful container orchestration tool used to manage containerized applications. In this blog series, we will be using Docker as our containerization tool, therefore, having a basic understanding of Docker and its concepts would be beneficial.</p><h3><strong>Introduction</strong></h3><p>Kubernetes is an odd word. It simply stands for ‘Helmsman’ or ‘Pilot’ in Greek. It makes sense since containers are often managed and delivered by a helmsman or a pilot. 🙂</p><p>Kubernetes, often abbreviated as “K8s”, containerizes applications to run on a cluster of hosts. From now on let us use K8s instead of Kubernetes. The K8s system automates the deployment and management of cloud-native applications using on-premises infrastructure or public cloud platforms. It distributes application workloads across a Kubernetes cluster and automates dynamic container networking needs. Kubernetes also allocates storage and persistent volumes to running containers, provides automatic scaling, and works continuously to maintain the desired state of applications, providing resiliency.</p><h3><strong>Kubernetes Distributions</strong></h3><p>Containerization is a really good technology, and K8s is taking the industry by storm. As Kubernetes began to increase in popularity and wide adoption, all the major cloud solution providers started to adapt and provide native Kubernetes support to their ecosystems. Apart from these services, many distributions were released.</p><ul><li>Kubeadm</li><li>Kops</li><li>Kube-aws</li><li>Minikube</li><li>MicroK8s</li><li>AWS EKS</li><li>Azure AKS</li><li>Google Kubernetes Engine (GKE) and many more…</li></ul><p>So, now what? Do I have to learn about all of them 😐. Well, all of them are K8s. There are some differences among them. But learning the fundamentals and the internals is more than enough.</p><p>We will be using MicroK8s for this series. You can also use Minikube if you really like it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-AMAQD52RDX59T0R5fz6w.png" /><figcaption>(Source : <a href="https://imgflip.com/memegenerator/332730230/Little-guy-big-guy">imgflip</a>)</figcaption></figure><h3><strong>Why use MicroK8S?</strong></h3><p>MicroK8s is a lightweight, fast, and secure Kubernetes distribution developed by Canonical, the company behind Ubuntu. It is a zero-ops K8s cluster. It can be used for a variety of reasons, such as,</p><ol><li>Easy setup and installation: MicroK8s can be installed on a single node with a single command, which makes it very easy to get started with Kubernetes.</li><li>Development and testing: MicroK8s is a great tool for developers who want to test their Kubernetes applications without having to set up a full-blown Kubernetes cluster.</li><li>Resource efficiency: MicroK8s is designed to be lightweight and resource-efficient, which means it can be run on a low-powered machine or a virtual machine without any issues. You can even use this on a Raspberry Pi 🫢</li><li>Security: MicroK8s comes with a number of security features, such as automatic updates, RBAC (Role-based access control) , and pod security policies, which makes it a good choice for deploying secure applications.</li><li>Local development: MicroK8s can be used for local development, allowing developers to test their applications in a Kubernetes environment before deploying them to a production cluster.</li></ol><p>Overall, MicroK8s is a great choice for developers and system administrators who want a lightweight, easy-to-use, and secure Kubernetes distribution. It is mostly used for prototyping, offline deployments and testing purposes.</p><blockquote>ZeroOps: <strong>A set of practices that result in developers focusing solely on coding and creating, with 0% of their time spent on operations or infrastructure</strong>.</blockquote><p>Now, let us install MicroK8s. I will include all the steps and commands for the process.<a href="https://microk8s.io/"> https://microk8s.io/</a> Visit the official website for instructions you need to follow in order to install microK8S on your development environment.</p><p>The following steps are for Ubuntu. (Tested on Ubuntu 22.02)</p><pre>sudo snap install microk8s --classic --channel=1.26<br>sudo usermod -a -G microk8s $USER<br>sudo chown -f -R $USER ~/.kube</pre><p>After this, you need to restart the terminal. Just close the current one and open a new one. Or</p><pre>su - $USER</pre><p>Running these commands will install MicroK8S 1.26 on your Ubuntu environment. This is the current latest and stable version by the time I’m writing this article.</p><pre>microk8s status --wait-ready</pre><p>With this, you will get installed MicroK8S environment details after the installation is completed. *It might take a few minutes to be ready. 🤓</p><p>Now let us verify the MicroK8s installation with a simple deployment.</p><p>Consider the following Manifest file containing a simple busy-box deployment,</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: busybox-pod<br>spec:<br>  containers:<br>    - name: busybox-container<br>      image: busybox<br>      command: [&quot;sleep&quot;, &quot;3600&quot;]</pre><ul><li>Copy the code and create a yaml file. Let’s name it busy-pod.yaml .</li><li>Deploy it with</li></ul><pre>microk8s kubectl apply -f busy-pod.yaml</pre><ul><li>Verify the pod status</li></ul><pre>microk8s kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0A3uemwz3kJ3I43h2glTlQ.png" /></figure><p>With this you can list out all the pods in the defaut namespace.</p><ul><li>Test the deployment</li></ul><pre>microk8s kubectl exec -it busybox-pod -- sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTwKaunS8xtHS5ApTT8RUA.png" /></figure><p>Use <strong><em>exit</em></strong> command to get back to your terminal.</p><h3>K8s Basic Architecture</h3><p>Let us look at the basic architecture of a Kubernetes cluster. <strong>Please keep in mind that the actual architecture in MicroK8s is somewhat different.</strong> Don’t worry, we will talk about them when describing the components.</p><figure><img alt="Architecture of K8s https://github.com/NuwanUdara/my-diagrams/blob/main/kube" src="https://cdn-images-1.medium.com/max/1024/1*4TQLgiWiQu4_ehbdUx7r0w.png" /><figcaption>Kubernetes Basic Architecture (Source: Author)</figcaption></figure><p><em>This diagram can be found </em><a href="https://github.com/NuwanUdara/my-diagrams/blob/main/kube"><em>here</em></a><em>.</em></p><p>Now we have a bunch of new words to deal with. Also, this seems confusing. In the beginning, I was too. Well, you can make sense of all the things here when you start to work with K8s. You don’t have to know all these things to work with K8s. 😊</p><p>But, when you work with production, you must have a good understanding of the architecture of a K8s cluster. If you don’t think you need these right now, can skip this section and carry on with part 2. But, at least come later, this stuff is important in the long run.</p><h4>Cluster</h4><p>Microk8s is defined as a single node cluster. Well, you can add more nodes and expand the cluster, but the specialty of MicroK8s is it has awesome features and support to run on a local node.</p><p>A cluster in the context of Kubernetes refers to a group of interconnected computing nodes (typically virtual or physical machines) that work together to run containerized applications.A cluster is managed by the Control Plane components, such as the API Server, Scheduler, and Controller Manager, which collectively control the overall state and behavior of the cluster. The Control Plane components interact with each other and with the worker nodes to ensure that containers are deployed, scaled, monitored, and managed according to the desired state defined in the cluster’s configuration.</p><p><em>To add more nodes to your Microk8s Cluster, Run the following from the Master node,</em></p><pre>microk8s add-node </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mnV1NC-DbluG88pGwanmYQ.png" /><figcaption>Add a node (Source : Author)</figcaption></figure><p><em>You can add more worker nodes by following the instructions.</em></p><h4>KubeCTL</h4><p><strong>Role</strong>: Command-line tool for managing Kubernetes resources</p><p><strong>Functionality</strong>: Sends commands and queries to the Kubernetes API Server to manage resources in the cluster, such as creating, updating, and deleting pods, services, and other Kubernetes objects.</p><p>Microk8s comes with its own kubectl binary. You can use aliases to create a shortcut, but I prefer to keep the longer version. (use whatever you like) 🫠</p><pre>alias kubectl=&#39;microk8s kubectl&#39;<br>alias k=&#39;microk8s kubectl&#39;</pre><p>We will follow more on the kubectl in later sections.</p><h4>Control Plane ( Master Node )</h4><p><strong>Role:</strong> Central management component of the Kubernetes cluster</p><p><strong>Functionality:</strong></p><ul><li>API Server: Provides a RESTful endpoint for the Kubernetes API, validates and processes incoming requests from various components and users.</li><li>etcd: Stores configuration data of the cluster, including metadata, configuration settings, and state information.</li><li>Scheduler: Places pods onto worker nodes based on predefined rules and policies, monitors the cluster for new pod requests, and makes decisions on where to deploy them.</li><li>Cloud Controller Manager: Interacts with cloud providers to manage cloud-specific resources in the cluster, such as load balancers, volumes, and virtual machines.</li><li>Controller Manager: Manages various controllers that automate tasks in the cluster.</li></ul><p>These specifications are targeted at general Kubernetes. But we are focusing on <strong>Microk8s </strong>🫢. Here are some notes to keep in mind about the Microk8s.</p><ol><li>etcd: In the earlier builds, etcd was the main key value storing service in the Microk8s. But after 1.19 stable release, etcd was replaced with <strong><em>dqlite </em></strong>as the default key-value pair database. etcd is still available, but we need to disable <strong><em>HA-cluster</em></strong> add-on to change it back.🫤 dqlite is a distributed SQlite database.</li><li>Cloud Controller Manager: MicroK8s does not include the Cloud Controller Manager, as it is specifically designed for managing cloud-specific resources in a Kubernetes cluster. Since MicroK8s is intended for local development and testing, it does not interact with cloud providers for managing cloud-specific resources. There will be support in the future for a CCM inside MicroK8s, but for now, there is no official support.🫡</li><li>High Availability: MicroK8s is designed to run on a single node by default. But as I mentioned earlier you are free to add more nodes and form a cluster. With etcd+flamal being replaced with dqlite and calico, the HA-cluster will let you form a multi-node cluster. This feature was released with Microk8s 1.19 version.</li></ol><p>We will get into add-ons in the next section. So, for now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*2e-rGixo6j53z_ko.gif" /><figcaption>Forget about it (Source: Author)</figcaption></figure><p>MicroK8s aims to provide a simple and easy-to-use Kubernetes environment, with minimal configuration and setup required. This may result in some differences in terms of configuration options, defaults, and behaviors compared to a full-fledged Kubernetes cluster.😊</p><h4>etcd</h4><p><strong>Role:</strong> Distributed key-value store used for storing configuration data of the Kubernetes cluster</p><p><strong>Functionality: </strong>Stores the configuration data of the cluster, including metadata, configuration settings, and state information, in a distributed and highly available manner. etcd is a consistent and distributed key-value store that maintains a reliable and durable record of the cluster’s configuration data. It is used by the Control Plane components, such as the API Server, Scheduler, and Cloud Controller Manager, to store and retrieve information about the state of the cluster. etcd ensures that the cluster’s configuration data is stored securely, replicated across multiple nodes for fault tolerance, and accessible to the components that need to read or update the configuration data.</p><p>As mentioned before, MicroK8s uses <strong>dqlite </strong>to store the configuration data of its cluster. You can still enable the etcd support by disabling HA-cluster addon. But, in the etcd+flannel configuration, you will not form an HA cluster by just joining more than one node.</p><blockquote>HA<strong>-</strong>Cluster: <strong>High Availability Cluster is a group of hosts that act like a single system and provide continuous uptime</strong>.</blockquote><h4>API Server</h4><p><strong>Role:</strong> The interface that allows components within the cluster to communicate with each other</p><p><strong>Functionality:</strong> Exposes a RESTful endpoint for the Kubernetes API, receives requests from kubectl and other components, authenticates and authorizes incoming requests, and communicates with etcd to store and retrieve configuration data of the cluster.</p><p>API Server has a significant role in by providing a communication medium to the Cluster components. Due to this nature, there is isolation between components in a cluster because of the API server and restriction on outside interference on the cluster.</p><h4>Scheduler</h4><p><strong>Role: </strong>The scheduler is responsible for placing pods onto worker nodes in the cluster based on predefined rules and policies.</p><p><strong>Functionality:</strong> The scheduler monitors the cluster for new pod requests, evaluates the available resources on worker nodes, and makes decisions on where to deploy the pods based on factors such as resource availability, rules, labels, and other policies. By doing so, the scheduler ensures that pods are evenly distributed across worker nodes and that resources are utilized efficiently.</p><p>You can refer to <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kube-scheduler/">the official documentation</a> to explore more on K8s scheduler.</p><h4>Controller Manager</h4><p><strong>Role: </strong>Manages various controllers that automate tasks in the cluster. The central unit of automation.</p><p><strong>Functionality:</strong> Runs several built-in controllers that automate tasks in the cluster, such as the Replication Controller, DaemonSet, Job, and Deployment controllers. These controllers monitor the state of the cluster and automatically reconcile the desired state with the current state, ensuring that the cluster maintains the desired state.</p><p>For example, the Replication Controller ensures that the specified number of replicas of a pod is running at all times. If a pod dies due to some reason, the replication controller will see that there is a missing pod and will try to start a new pod with the provided specification. The Controller Manager in MicroK8s automates these tasks and helps maintain the desired state of the cluster based on the defined configurations. Refer to <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/">this</a> article to get all available controllers.</p><h4>Kubelet</h4><p><strong>Role: </strong>Agent running on each Worker Node that communicates with the Control Plane and manages containers on the node.</p><p><strong>Functionality:</strong> Monitors the state of pods and containers on the Worker Node, ensuring that they are running and healthy as per the desired state defined in the pod specification. It communicates with the Control Plane to report the state of the node and receive instructions for starting, stopping, or restarting containers. It also handles container lifecycle operations, such as pulling container images, mounting volumes, and monitoring container health.</p><p>You can get more information on kubelet from the <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/">official documentation</a>.</p><h4>Kube-Proxy</h4><p><strong>Role: </strong>Manages network communication within the cluster and exposing.</p><p><strong>Functionality: </strong>Maintains network routing and load-balancing for pods, exposes services to the network, and ensures efficient and secure communication between containers and pods. Communicates with the API Server to receive instructions and update network configurations and works in conjunction with other components to ensure proper networking in the cluster.</p><p>🕷️ With great power comes great responsibility. The kube proxy is responsible for security features that come with this isolation.</p><ul><li>It will ensure that pods can communicate with cluster-ips on the same nodes without hassle, but it won’t allow direct communication with pods in different pods without going through a network gateway.</li><li>A typical Kubernetes cluster uses the kube-proxy as its most fundamental default load balancing method. All requests made to the Kubernetes service are processed and routed by the kube-proxy.</li></ul><blockquote><strong>Cloud providers offer their own load-balancing solutions. </strong><br>For instance, AWS provides Elastic Load Balancers (ELBs), which can effectively distribute traffic across multiple targets. In Kubernetes (K8s) environments on these platforms, ELBs are commonly utilized to handle load-balancing services.<br>To handle OSI Layer 4 (L4) traffic, you can leverage the Network Load Balancer (NLB) through a load balancer service. NLB operates at the transport layer and effectively balances traffic at the IP protocol level. (read more <a href="https://docs.aws.amazon.com/eks/latest/userguide/network-load-balancing.html">NLB</a> )<br>For OSI Layer 7 (L7) traffic, the Application Load Balancer (ALB) is used in conjunction with an Ingress service. ALB operates at the application layer and enables advanced routing and load-balancing based on HTTP/HTTPS requests. (read more <a href="https://docs.aws.amazon.com/eks/latest/userguide/alb-ingress.html">ALB</a> )</blockquote><ul><li>It also enforces RBAC ( Role-based access control ) and reduces unauthorized outside interference.</li></ul><p>For more information, <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/">here</a> is the official documentation. Also, <a href="https://mayankshah.dev/blog/demystifying-kube-proxy/">this</a> article will clear most of the doubts you have.</p><p>Well, let’s start exploring more on Microk8s. Hope to see you again in the next section. 👋</p><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqSn9Ge7nAks%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqSn9Ge7nAks&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqSn9Ge7nAks%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b17549096f35ff40e4ee3a38bbb48e7b/href">https://medium.com/media/b17549096f35ff40e4ee3a38bbb48e7b/href</a></iframe><ul><li><a href="https://microk8s.io/docs/configuring-services">MicroK8s - Configuring MicroK8s services | MicroK8s</a></li><li><a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/">kube-controller-manager</a></li><li><a href="https://benbrougher.tech/posts/microk8s-6-months-later/">Switching to microk8s - 6 Months Later | benbrougher.tech</a></li><li><a href="https://microk8s.io/docs/release-notes">MicroK8s - Release notes | MicroK8s</a></li><li><a href="https://github.com/canonical/microk8s/issues/1671">Microk8s 1.19 starting with ha-cluster enabled by default. why?? · Issue #1671 · canonical/microk8s</a></li><li><a href="https://github.com/canonical/microk8s">GitHub - canonical/microk8s: MicroK8s is a small, fast, single-package Kubernetes for datacenters and the edge.</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c40a1ed54c38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yaalalabs/get-started-with-kubernetes-and-microk8s-a-beginners-guide-to-container-orchestration-c40a1ed54c38">Get Started with Kubernetes and MicroK8s: A Beginner’s Guide to Container Orchestration</a> was originally published in <a href="https://medium.com/yaalalabs">Yaala Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sample Application With MySQL, Node.Js and React.Js - Phase 01]]></title>
            <link>https://nu1udara.medium.com/sample-application-with-mysql-node-js-and-react-js-7824f9b8bac6?source=rss-1a791f92e1b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7824f9b8bac6</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[hello-world]]></category>
            <dc:creator><![CDATA[Nuwanudara]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 10:37:56 GMT</pubDate>
            <atom:updated>2023-03-30T11:25:01.949Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a simple React.Js, Node.js and MySQL application guide for beginners. We will use this application for future projects as well. Stay tuned. Please keep in mind that this is not a java-script tutorial. In the next article, we will Dockerize this application.</p><p>alt picture.</p><p>Prerequisites</p><ul><li><em>NodeJs</em></li><li><em>MySQL server</em></li><li><em>MySQL Workbench ( It will help )</em></li><li><em>Good Code editor ( I prefer VS Code )</em></li></ul><p><strong>Step 1</strong></p><p>Create The front end.</p><p>At this stage I hope you have npm and Nodejs installed. If not comeback after doing so. Make a parent folder lets name it “Application”. Inside that folder, create another folder. Name it, “client”. And another folder “server”. These will be used to store our Back-end and Front-end. open it in VS Code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rf3eqiWWcvnvluL97lTuxg.png" /></figure><p>It will look something like this. Now open a terminal inside vscode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*oAcMSprAVmJbCkWlRDkAXw.png" /></figure><p>Click on new terminal, this will attach a terminal to your vscode Application/ directory. After that navigate inside your client folder by</p><pre>cd client/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*r11_j7ukiC2NTl2rRTaVxQ.png" /></figure><p>Now, we can create our react application with npx command. This will give us a template react.js application to work with. type following command and wait till the process is completed.</p><pre>npx create-react-app .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHVjZrAGEGyWExxRzfvRWg.png" /></figure><p>Wait till the process is done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z1pcw5_v0MpdceqapYeIzw.png" /></figure><p>Now, we will remove and add files, edit files. Copy the codes and paste them accordingly. There will be a explanation after words.</p><p><strong><em>remove following files from the src folder, <br>- index.css <br>- setupTests.js<br>- logo.svg<br>- App.test.js</em></strong></p><p>And it will look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*TREfK9gMYPeqFQTUH71hNA.png" /></figure><p>After that, open App.js file and replace the content with the following code.</p><pre>import &quot;./App.css&quot;;<br>import { useState } from &quot;react&quot;;<br>import Axios from &quot;axios&quot;;<br><br>function App() {<br>  const [name, setName] = useState(&quot;&quot;);<br>  const [age, setAge] = useState(0);<br>  const [quo, setQuo] = useState(&quot;&quot;);<br>  const [QuoList,setQuoList] = useState([])<br><br>  const ColoredLine = ({ color }) =&gt; (<br>    &lt;hr<br>        style={{<br>            color: color,<br>            backgroundColor: color,<br>            height: 1,<br>            width: 600<br>        }}<br>    /&gt;<br>);<br><br>  const addquo = () =&gt; {<br>    Axios.post(&quot;http://localhost:3001/create&quot;, {<br>      name: name,<br>      age: age,<br>      quote: quo,<br>    }).then(()=&gt;{<br>      console.log(&quot;success!&quot;);<br>    })<br>  };<br><br>  const getquo = () =&gt; {<br>    Axios.get(&quot;http://localhost:3001/quote&quot;).then((response)=&gt;{<br>      console.log(response);<br>      setQuoList(response.data);<br><br>    })<br>  };<br><br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;div className=&quot;info&quot;&gt;<br>        &lt;label&gt;Name:&lt;/label&gt;<br>        &lt;input<br>          type=&quot;text&quot;<br>          onChange={(event) =&gt; {<br>            setName(event.target.value);<br>          }}<br>        /&gt;<br><br>        &lt;label&gt;Age:&lt;/label&gt;<br>        &lt;input<br>          type=&quot;number&quot;<br>          onChange={(event) =&gt; {<br>            setAge(event.target.value);<br>          }}<br>        /&gt;<br><br>        &lt;label&gt;Quote:&lt;/label&gt;<br>        &lt;input<br>          type=&quot;text&quot;<br>          onChange={(event) =&gt; {<br>            setQuo(event.target.value);<br>          }}<br>        /&gt;<br>        &lt;button onClick={addquo}&gt;Add Quote&lt;/button&gt;<br>      &lt;/div&gt;<br>      &lt;ColoredLine color=&quot;red&quot; /&gt;<br>      &lt;div className=&quot;quo&quot;&gt;<br>        &lt;button onClick={getquo}&gt; Show All&lt;/button&gt;<br>        {QuoList.map( (val,key) =&gt; {<br>          return &lt;div className=&quot;getq&quot;&gt; <br>          &lt;h3&gt;{val.name}&lt;/h3&gt;<br>          &lt;h4&gt;{val.quot}&lt;/h4&gt;<br>          &lt;/div&gt;<br>        })}<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>explanation!</p><p>Here, The logo file is removed and, has imported useState function and axios library. The axios is a famous library, we use it to make api calls to our Back-end. You will make get and post requests to our Back-end application and get data and send data from it and to it.</p><p>In React, useState is a hook that allows you to add state to functional components. State is a way of storing and managing data that can change over time and affect the behavior of the component. In a nutshell, you can pass values and get values using these, useState(0) mean that, at the start, age variable is set to 0.</p><pre>&lt;input<br>          type=&quot;number&quot;<br>          onChange={(event) =&gt; {<br>            setAge(event.target.value);<br>          }}<br>        /&gt;</pre><p>This right here will set value to variable ‘age’ from the input field. It will trigger on change of the input field content. Now, we imported a 3rd party library, but we forgot to install it. Go ahead and run following on your terminal.</p><pre>npm install axios</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*nkC1sRI3m_XkejZi90MlEA.png" /></figure><p>And go ahead and modify following files as well.</p><p><em>App.css</em></p><pre>.App {<br>  display: flex;<br>  flex-direction: column;<br>  justify-content: center;<br>}<br><br>.info{<br>  display: flex;<br>  flex-direction: column;<br>  align-items: center;<br>}<br> .info input{<br>  width: 300px;<br>  height: 30px;<br>  font-size: 20px;<br>  padding-left: 10px;<br>  margin: 5px;<br> }<br><br> .info button{<br>  width:200px ;<br>  height: 30px;<br>  margin-top: 10px;<br> }<br><br> .info button:hover{<br>   cursor: pointer;<br>   color: blue;<br> }<br><br> .quo{<br>  display: flex;<br>  flex-direction: column;<br>  align-items: center;<br>  width: 100%;<br> }<br><br> .getq{<br>  display: flex;<br>  flex-direction: column;<br>  width: 90%;<br>  align-items: center;<br>  border: 1px solid black;<br>  margin: 2px;<br>  color-scheme: dark;<br>  color: rebeccapurple;<br>  font-family: &#39;Courier New&#39;, Courier, monospace;<br>  text-align: center;<br> }</pre><p><em>index.js</em></p><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom/client&#39;;<br>import App from &#39;./App&#39;;<br>import reportWebVitals from &#39;./reportWebVitals&#39;;<br><br>const root = ReactDOM.createRoot(document.getElementById(&#39;root&#39;));<br>root.render(<br>  &lt;React.StrictMode&gt;<br>    &lt;App /&gt;<br>  &lt;/React.StrictMode&gt;<br>);<br>reportWebVitals();</pre><p>All done for now. You can check your Front-end by running,</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjmomLupJX6L7EEY6N0J-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7q5iTEKtOCGn6EM4_WkKqg.png" /></figure><p>Feel free to modify how things look. You can use App.css to do most of the customization.</p><p><strong>Step 2</strong></p><p>Creating the Back-end.</p><p>Now, goto your terminal and</p><pre>cd ..<br>cd server/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*OwlpgxPX4nCh5MrVYQBspg.png" /></figure><p>and navigate to you server folder. After that run</p><pre>npm init -y</pre><p>With this, you can setup your node.js application quickly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*AnUTVr2QnIBUkpt96kRJ9A.png" /></figure><p>Go ahead and edit the package.json file,</p><pre>{<br>  &quot;name&quot;: &quot;server&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>    &quot;start&quot;: &quot;node index.js&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><p>The main javascript file will be the index.js and we are giving here a command for the application to start, which we can later call with <br>“npm start”</p><p>Next we need to install all the librarians we will be using for our Back-end application. Run following on your terminal,</p><pre>npm install cors mysql2 express</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isAhiYUeG4SXuLsiV7v_pw.png" /></figure><p>As you can see, the package.json is updated. Also, node_modules folder is created along side package-lock.json.</p><p>Next, go ahead and create a new file inside the server folder, with</p><pre>touch index.js</pre><p>Add the following code to the index.js</p><pre>const express = require(&quot;express&quot;);<br>const mysql = require(&quot;mysql2&quot;);<br>const cors = require(&quot;cors&quot;);<br><br>const db = mysql.createConnection({<br>  user: &quot;root&quot;,<br>  host: &quot;localhost&quot;,<br>  password: &quot;password&quot;,<br>  database: &quot;mydatabase&quot;,<br>  port: 3306<br>});<br><br>const app = express();<br>app.use(cors())<br>app.use(express.json())<br>app.post(&quot;/create&quot;, (req, res) =&gt; {<br>  console.log(&quot;Got the response&quot;)<br>  const name = req.body.name;<br>  const age = req.body.age;<br>  const quot = req.body.quote;<br>  db.query(&quot;INSERT INTO myquo (name,age,quot) VALUES (?,?,?)&quot;, <br>  [name, age, quot],(err,result)=&gt; {<br>    if(err){<br>        console.log(err);<br>    }<br>    else{<br>        res.send(&quot;value Inserted&quot;).status(200);<br>    }<br>  }<br>  );<br>});<br><br>app.get(&#39;/quote&#39;, (req,res) =&gt; {<br>  db.query(&#39;SELECT * FROM myquo&#39;,(err,result) =&gt; {<br>    if (err){<br>      console.log(err);<br>    }<br>    else{<br>      console.log(result);<br>      res.send(result);<br>    }<br>  })<br>})<br><br>app.listen(3001, () =&gt; {<br>  console.log(&quot;It&#39;s running on 3001&quot;);<br>});</pre><p>Here, we are using 3 main libraries for our application. express, mysql2 and cors.</p><p><strong>Express:</strong></p><p>Express is an easy to learn flexible back-end api server framework. With this, we can listen on a port of our computer and accept requests send by Front-end with axios library.</p><p><strong>CORS:</strong></p><p>It is a middle-ware. What is a middle-ware? Well express middle-ware execute functions during the processing of HTTP requests received to the express application. It stands for Cross-Origin Resource Sharing, It will let applications to talk between each other through tools such as web browsers, by relaxing security and allow access to the resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*Blqo2oudfH9UXA53GJXYxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*i3KlBNSPslsAHlmnvgYAqQ.png" /></figure><p>With CORS library, we can enable communication between our Front-end and Back-end they are running on different ports.</p><p><strong>MYSQL2:</strong></p><p>MySQL2 library is a continuation of native MySQL library. It has better features and performance than the older MySQL library. We are connecting to a local MySQL server, in the next step we will install MySQL server and configure it for our application.</p><p><strong>Step 3</strong></p><p>Install a MySQL server, if not available one. Open a terminal and do the following.</p><pre>sudo apt install mysql-server -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J97-J7Ea_VtgVtG9MzY1_w.png" /></figure><p>Give a password for your root user, We are using a simple password for the time being, add “password” as your root password for this example. You are free to use whatever password you like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YnTjN0LxIUKs292-BH5kAw.png" /></figure><p>Use this option as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8nsAALqVUxlo5X2RGfwtQ.png" /></figure><p>It is installed. You can check the status by,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*ZV38w0XZlst9ZSkZ29olsw.png" /></figure><pre>sudo service mysql status</pre><p>Next, install MySQL workbench. Use this <a href="https://dev.mysql.com/downloads/workbench/">link</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*eTzlchnAWDdWjDDQVUKE6A.png" /></figure><p>Choose your Operating system and grab a package that suites your architecture. Now, install the package. After that open the mysql workbench.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ov_HFWbmRpvwF-_e4zP1Bw.png" /></figure><p>If the server was installed successfully, and running properly, you will be able to see Local instance on 3306 port. Click on it and provide the root password we gave earlier. What I used was “password”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*BuUAN1fJVNpqZFSg08WU5g.png" /></figure><p>Go to schema by swapping the administrator tab arrow. After that create a Schema. This will be your database. We will create a table inside the database to store our data.</p><p>Create Schema -&gt; Schema Name “mydatabase” -&gt; Apply -&gt; Apply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1UtjI_0WYxJooQKqZhzwg.gif" /></figure><p>Next create a table,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*eyOfTWE1SpH9QYpJVbeKjw.png" /></figure><p>Set up the name of the table to be “myquo”, add “id” , “name”, “age” and “quot” field in the table. And mark the check boxes like below, and apply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-JA8ZtjHEVl7WOr7v7BDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*VLYXDRxa_ub3pmO2hA_bxw.png" /></figure><p>After this, you are good to go.</p><p>If you do not want to use the workbench and use the default terminal, run following commands on your</p><pre>mysql -uroot -ppassword</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*-2UfhH9nXU9x63NmAFeJyw.png" /></figure><p>After that, you can use following commands to create your table</p><pre>CREATE DATABASE IF NOT EXISTS mydatabase;<br>USE mydatabase;<br>CREATE TABLE IF NOT EXISTS myquo (id int NOT NULL AUTO_INCREMENT, name text(256) NOT NULL, quot text(2500) NOT NULL, age int, PRIMARY KEY (id) );</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F2WT1w4gKefcwBe_VoDgjg.png" /></figure><p>IF NOT EXISTS keyword will create only if there is no resources with the same name.</p><p>Now you are good to go.</p><p><strong>Step 4</strong></p><p>Running the application, open your VS code and make sure you are in the server folder. After that use</p><pre>npm start</pre><p>to start the Back-end and. Open a second terminal and go to Client folder using the cd commands and run the Front-end using the same command.</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DlUObh_cLe7T-vkCJzu1SA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bAJ2W6G16QaXHsZnzmNztA.png" /></figure><p>If all the 3 services are running, Add a quote,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sCFvz1Au77r69MyGyEn-hw.png" /></figure><p>Using Show All you can list your added quotes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-De1dmb59NTWb0izamcMKA.png" /></figure><p>Go ahead and try to modify and improve the looks, responses and the algorithm and keep “Happy Hacking!” 😉</p><p>GitHub <a href="https://github.com/NuwanUdara/Application-stage-1.git">link</a> for the project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7824f9b8bac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This one is reserved.]]></title>
            <link>https://nu1udara.medium.com/testing-my-first-blog-post-f23ca4a3649d?source=rss-1a791f92e1b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f23ca4a3649d</guid>
            <dc:creator><![CDATA[Nuwanudara]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 10:31:12 GMT</pubDate>
            <atom:updated>2023-04-19T10:41:18.631Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, how are you?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f23ca4a3649d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>