<?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>Forem: Josué Makuta</title>
    <description>The latest articles on Forem by Josué Makuta (@joemakuta).</description>
    <link>https://forem.com/joemakuta</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%2F1092226%2Fdd59b097-4c7c-4195-a722-54484b53c17a.jpg</url>
      <title>Forem: Josué Makuta</title>
      <link>https://forem.com/joemakuta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joemakuta"/>
    <language>en</language>
    <item>
      <title>What Happens When You Type www.google.com and Press Enter?</title>
      <dc:creator>Josué Makuta</dc:creator>
      <pubDate>Fri, 13 Oct 2023 15:22:23 +0000</pubDate>
      <link>https://forem.com/kadea-academy/what-happens-when-you-type-wwwgooglecom-and-press-enter-7oa</link>
      <guid>https://forem.com/kadea-academy/what-happens-when-you-type-wwwgooglecom-and-press-enter-7oa</guid>
      <description>&lt;p&gt;Have you ever wondered what happens when you type &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt; and press enter? &lt;br&gt;
It may seem like a simple process, but there are many steps involved in making this happen. In this article, we will take a closer look at the different components that come into play when you type a URL into your browser and press enter.&lt;/p&gt;

&lt;p&gt;Without further ado, let's jump into it&lt;/p&gt;

&lt;p&gt;The first thing that happens when you type &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt; is that your browser sends a DNS (Domain Name System) request to a DNS server. Now, what is a DNS server ? How does it work ? Why do we need it ?&lt;/p&gt;

&lt;h2&gt;
  
  
  1. DNS Server
&lt;/h2&gt;

&lt;p&gt;The DNS server is responsible for translating the domain name (&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;) into an IP address that your computer can understand. This is necessary because computers communicate with each other using IP addresses eg : &lt;code&gt;192.168.0.0&lt;/code&gt; , not domain names. &lt;/p&gt;

&lt;p&gt;Once your browser has the IP address for &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;, it establishes a TCP (Transmission Control Protocol) connection with the server hosting the website. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. TCP/IP
&lt;/h2&gt;

&lt;p&gt;TCP is a protocol that ensures reliable communication between two devices over a network. It breaks data into packets and sends them across the network, reassembling them at the other end. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Firewall
&lt;/h2&gt;

&lt;p&gt;Before the connection is established, your computer's firewall may check to see if the connection is allowed. A firewall is a security system that monitors and controls incoming and outgoing network traffic. If the firewall determines that the connection is not allowed, it will block the connection. &lt;/p&gt;

&lt;h2&gt;
  
  
  4. HTTPS/SSL
&lt;/h2&gt;

&lt;p&gt;If the connection is allowed, your browser will attempt to establish an HTTPS (Hypertext Transfer Protocol Secure) connection with the web server. HTTPS is a secure version of HTTP, which is the protocol used to transfer data between your browser and the web server. HTTPS uses SSL (Secure Sockets Layer) or TLS (Transport Layer Security) to encrypt the data being sent between your browser and the web server. This ensures that the data cannot be intercepted and read by anyone who may be listening on the network. &lt;/p&gt;

&lt;h2&gt;
  
  
  5. Load-Balancer
&lt;/h2&gt;

&lt;p&gt;Once the HTTPS connection is established, your request is sent to a load-balancer. A load-balancer is a device that distributes incoming network traffic across multiple servers. This is done to ensure that no single server becomes overloaded and that the website remains available to users. Load-balancers use various algorithms to determine which server should handle each request, such as round-robin, least connections, or IP hash. &lt;/p&gt;

&lt;h2&gt;
  
  
  6. Web Server
&lt;/h2&gt;

&lt;p&gt;The load-balancer forwards your request to one of the web servers hosting the website. The web server is responsible for processing your request and generating a response. This response may include HTML, CSS, JavaScript, images, or other resources that make up the website. Web servers like Apache, Nginx, or Microsoft IIS handle the request and serve the appropriate files to your browser. &lt;/p&gt;

&lt;h2&gt;
  
  
  7. Application Server
&lt;/h2&gt;

&lt;p&gt;If the website has dynamic content, your request may be forwarded to an application server. An application server is a server that runs applications that generate dynamic content. These applications may include server-side scripting languages like PHP, Python, or Java. The application server may interact with a database to retrieve data that is used to generate the response. &lt;/p&gt;

&lt;h2&gt;
  
  
  8. Database
&lt;/h2&gt;

&lt;p&gt;If the application server needs to retrieve data from a database, it sends a request to the database server. The database server retrieves the requested data and sends it back to the application server, which uses it to generate the response. Databases like MySQL, PostgreSQL, or MongoDB are commonly used to store and retrieve data for dynamic websites. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;As you can see, there are many steps involved in the process of loading a website. From the DNS request to the database server, each component plays a crucial role in ensuring that the website is loaded quickly and reliably. Understanding how these components work together can help you troubleshoot issues when they arise and appreciate the complexity of the modern web. Next time you type &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt; and press enter, you'll have a better understanding of the behind-the-scenes processes that make it all possible.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to expose Vite local instance to the network, Eg. Mobile Device</title>
      <dc:creator>Josué Makuta</dc:creator>
      <pubDate>Tue, 30 May 2023 10:17:02 +0000</pubDate>
      <link>https://forem.com/kadea-academy/how-to-expose-vite-local-instance-to-the-network-eg-mobile-device-if4</link>
      <guid>https://forem.com/kadea-academy/how-to-expose-vite-local-instance-to-the-network-eg-mobile-device-if4</guid>
      <description>&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A640%2Fformat%3Awebp%2F1%2ArO43wl8fR91WzCnEkZD7ng.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A640%2Fformat%3Awebp%2F1%2ArO43wl8fR91WzCnEkZD7ng.png" alt="Vite logo" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Vite (the French word for “fast”) is a new build tool for frontend web development.&lt;/p&gt;

&lt;p&gt;Vite &lt;strong&gt;promotes a faster development experience&lt;/strong&gt; by setting up a development environment for frameworks like Vue, TezJS, and React and even for Vanilla JavaScript apps with a dev server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Learn more about Vite here …&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vite local instance exposition
&lt;/h2&gt;

&lt;p&gt;When you configured your web application development using Vite, your &lt;code&gt;package.json&lt;/code&gt; file scripts look like this :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite preview"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


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

&lt;/div&gt;

&lt;p&gt;Now when you run the command :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm run dev


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

&lt;/div&gt;

&lt;p&gt;Here’s what the output might look like :&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AhIyOVAyIMCPPuypGbVCdBw.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AhIyOVAyIMCPPuypGbVCdBw.png" alt="Image without local instance" width="681" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The local instance is now running on &lt;a href="http://localhost:5173/" rel="noopener noreferrer"&gt;http://localhost:5173/&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Note that it shows also the &lt;strong&gt;Network: Use&lt;/strong&gt; &lt;code&gt;— host&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What’s that?&lt;/strong&gt; Vite gives way to expose the local instance to the local network in cases where you would like to test or view your web application on another device, let’s say, on your mobile device.&lt;/p&gt;

&lt;h2&gt;
  
  
  There are 3 ways to do it:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;By adding &lt;code&gt;--host&lt;/code&gt;&lt;/strong&gt; option to the scripts section in &lt;code&gt;package.json&lt;/code&gt; as shown below :&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite --host"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite preview"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;By adding the following configuration in the vite.config.js file like so:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;server:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;host:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Lastly, you can use the --host option with the &lt;code&gt;npm run&lt;/code&gt; dev command like so.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm run dev &lt;span class="nt"&gt;--host&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now the output should look like this :&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A640%2Fformat%3Awebp%2F1%2A7isO4rIYMp76_cIHEKq6MA.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A640%2Fformat%3Awebp%2F1%2A7isO4rIYMp76_cIHEKq6MA.png" alt="Image with vite local instance exposed" width="623" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the Vite local instance is available on the network address provided.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hope you found this article helpful,&lt;/em&gt; 👏👏👏.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Thanks for reading!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Express JS: Request Object — Req</title>
      <dc:creator>Josué Makuta</dc:creator>
      <pubDate>Tue, 30 May 2023 09:44:20 +0000</pubDate>
      <link>https://forem.com/kadea-academy/express-js-request-object-req-3dfa</link>
      <guid>https://forem.com/kadea-academy/express-js-request-object-req-3dfa</guid>
      <description>&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F0%2AnkiUuuss7xPhbJdS" 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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F0%2AnkiUuuss7xPhbJdS" alt="Photo by Clément Hélardot on Unsplash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Express Js, What is it ?
&lt;/h2&gt;

&lt;p&gt;Express JS is a &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; framework designed to quickly build API’s web applications, cross-platform, mobile apps, and make node js easy. Express js framework makes the server-side (backend) management of applications easy.&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A640%2Fformat%3Awebp%2F1%2AmP9IItA6sPV0ZlP1ZEHTjg.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A640%2Fformat%3Awebp%2F1%2AmP9IItA6sPV0ZlP1ZEHTjg.png" alt="Logo expressjs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we know what is Express Js, Below is the overview of this module :&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is the Request Object in Express JS?&lt;/li&gt;
&lt;li&gt;How to use the Request Object Req.&lt;/li&gt;
&lt;li&gt;Most used properties of the Request Object&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;: Basics of Javascript, NodeJs, and Express Js&lt;/p&gt;

&lt;h2&gt;
  
  
  Request Object, What is it?
&lt;/h2&gt;

&lt;p&gt;Before diving into the ocean, we must understand the underlying concept of Express Js: &lt;a href="https://expressjs.com/en/guide/writing-middleware.html" rel="noopener noreferrer"&gt;Middleware&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In Express Js, Middlewares are functions that are executed after a request is sent to the server and before the server sends a response. They are between the user request and the server response and have access to them therefore they can modify them as shown below :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;User request &amp;gt;|&amp;lt; Middleware &amp;gt;|&amp;lt; Server response&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here is an example of middleware :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&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;From this code above, we have a middleware that prints out in the console the URL of the user request, app being the express application. Learn more about writing middleware &lt;a href="https://expressjs.com/en/guide/writing-middleware.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The req is an object that is passed as an argument to the middleware function, represents the HTTP request and has properties for the request such as query string, parameters, body, HTTP headers, and so on.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In this article, conventionally the object is referred to as reqbut its actual name is determined by the parameters of the callback function in which you’re working.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Properties of the Request Object
&lt;/h2&gt;

&lt;p&gt;The request object has multiple properties and each one has a specific purpose. To check all the properties of the request object, Here is a code that prints it out.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;req&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;Now let’s take an overview of some useful properties of the request object :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;req.path&lt;/strong&gt;&lt;br&gt;
Contains the path part of the request URL.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// example.com/users&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;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; '/users'&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;res.body&lt;/strong&gt;&lt;br&gt;
It holds key-value pairs of the data in the user request body. By default, it is undefined, and is populated when you use body-parsing middleware such as &lt;a href="https://expressjs.com/en/4x/api.html#express.json" rel="noopener noreferrer"&gt;express.json()&lt;/a&gt; or &lt;a href="https://expressjs.com/en/4x/api.html#express.urlencoded" rel="noopener noreferrer"&gt;express.urlencoded()&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is how it is used, the app is our express app.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// for parsing application/json&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; 
&lt;span class="c1"&gt;//for parsing application/x-www-form-urlencoded app.use(express.urlencoded({ extended: true }))&lt;/span&gt;
&lt;span class="c1"&gt;//Here is a post resquest, its middleware prints out the body of the requestThe request  object has multiple properties and each one has a specific purpose. To check all the properties of the request object, Here is a code that prints it out.&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;&lt;strong&gt;req.params&lt;/strong&gt;&lt;br&gt;
This property is an object containing properties mapped to the &lt;a href="https://expressjs.com/en/guide/routing.html#route-parameters" rel="noopener noreferrer"&gt;named route “parameters”&lt;/a&gt;. For example, if you have the route &lt;code&gt;/user/:name&lt;/code&gt;, then the “name” property is available as &lt;code&gt;req.params.name&lt;/code&gt;. This object defaults to {}.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// GET /user/tj&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;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'tj'&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;req.ip&lt;/strong&gt;&lt;br&gt;
Contains the remote IP address of the request.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; '127.0.0.1'&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;req.hostname&lt;/strong&gt;&lt;br&gt;
Contains the &lt;code&gt;hostname&lt;/code&gt; derived from the Host HTTP header.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// Host: "example.com:3000"&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;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'example.com'&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;req.headers&lt;/strong&gt;&lt;br&gt;
This object receives the headers from the client, i.e. the data sent by the browser.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; {&lt;/span&gt;
  &lt;span class="nl"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localhost:4200&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;keep-alive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cache-control&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;max-age=0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-ch-ua&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-ch-ua-mobile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;?0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-ch-ua-platform&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;"Linux"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;upgrade-insecure-requests&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-agent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-fetch-site&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-fetch-mode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;navigate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-fetch-user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;?1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sec-fetch-dest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;accept-encoding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gzip, deflate, br&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;accept-language&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;if-none-match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;W/"20-xayHqON6qb0v2OGf3SWBojKNliI"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;req.app&lt;/strong&gt;&lt;br&gt;
This property holds a reference to the instance of the Express application that is using the middleware.&lt;/p&gt;

&lt;p&gt;Let’s note that the express request object includes also some methods such as :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accepts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;acceptsCharsets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;charset&lt;/span&gt; &lt;span class="p"&gt;[,&lt;/span&gt; &lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;And so on …&lt;/p&gt;

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

&lt;p&gt;The request object req is generally passed to the middleware to enable the developer to modify or customize the req received to the server. It has multiple properties and each one has a specific purpose. So far we have seen some useful properties of that object but feel free to check all the properties of the request object in the official documentation of express.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hope you found this article helpful,&lt;/em&gt; 👏👏👏.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Thank you for reading !&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Recursion explained !</title>
      <dc:creator>Josué Makuta</dc:creator>
      <pubDate>Tue, 30 May 2023 09:14:34 +0000</pubDate>
      <link>https://forem.com/kadea-academy/recursion-explained--10nd</link>
      <guid>https://forem.com/kadea-academy/recursion-explained--10nd</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6ddre2tbb4kzw011t1o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6ddre2tbb4kzw011t1o.jpg" alt="Photo by Shahadat Rahman on Unsplash" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's talk a little bit about Recursion 😎
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Have you ever wondered what recursion is and how it works? If so, you are not alone. Recursion is one of the most powerful and elegant techniques in programming, but also one of the most confusing and intimidating for beginners.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, I will try to explain recursion in a simple and funny way, using examples that will hopefully make you laugh and learn at the same time.✌&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Recursion&lt;/strong&gt; is a method of solving problems by breaking them down into smaller and simpler sub-problems until they are so easy that they can be solved directly. Then, the solutions of the sub-problems are combined to form the solution to the original problem.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The key idea of recursion is that a function can call itself within its own definition. This is called a recursive call.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  A recursive function must have two parts: a base case and a recursive case.
&lt;/h3&gt;

&lt;p&gt;The base case is the simplest scenario where the function can return a value without calling itself. The base case acts as a stopping condition for the recursion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The recursive case&lt;/strong&gt; is where the function calls itself with a smaller or simpler input. The recursive case acts as a way to reduce the problem size and approach the base case.&lt;/p&gt;

&lt;h2&gt;
  
  
  An example of recursion
&lt;/h2&gt;

&lt;p&gt;Let's look at an example of recursion: calculating the factorial of a positive integer n. The factorial of n, denoted by n!, is the product of all positive integers from 1 to n.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;5! = 5 x 4 x 3 x 2 x 1 = 120.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;How can we write a recursive function to compute n!? Well, we can use the following observation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is our base case.&lt;/strong&gt;&lt;br&gt;
The factorial of 1 is 1. ⇒ &lt;code&gt;1! = 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is our recursive case.&lt;/strong&gt;&lt;br&gt;
The factorial of n is n times the factorial of n-1.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;5! = 5 * 4!&lt;br&gt;
4! = 4 * 3!&lt;br&gt;
3! = 3 * 2!&lt;br&gt;
2! = 2 * 1!&lt;br&gt;
1! = 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using these two facts, we can write a recursive function in pseudocode as follows:&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;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;// base case&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
  &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// recursive case&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&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;Let's see how this function works for n = 5. We start by calling factorial(5). Since 5 is not equal to 1, we enter the else branch and return 5 * factorial(4). But before we can evaluate this expression, we need to know what factorial(4) is. So we make another recursive call to factorial(4). This process repeats until we reach the base case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;factorial(5) = 5 * factorial(4)
= 5 * (4 * factorial(3))
= 5 * (4 * (3 * factorial(2)))
= 5 * (4 * (3 * (2 * factorial(1))))
= 5 * (4 * (3 * (2 * 1))) # base case reached
= 120
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, each recursive call reduces the problem size by one, until we reach the simplest case where we can return a value directly. Then, we use that value to compute the previous call, and so on, until we get back to the original call.&lt;/p&gt;

&lt;h2&gt;
  
  
  A funny analogy of recursion
&lt;/h2&gt;

&lt;p&gt;If you are still confused by recursion, don't worry. Here is a funny analogy that might help you understand it better.&lt;/p&gt;

&lt;p&gt;Imagine that you are in a room with a mirror on one wall. You decide to take a selfie with your phone, but you want to capture the mirror in the background. So you stand in front of the mirror and point your phone at it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yQZONXfM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fit:640/format:webp/1%2A1kZ0Q_JqOVaSg5oPivKR0w.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yQZONXfM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fit:640/format:webp/1%2A1kZ0Q_JqOVaSg5oPivKR0w.jpeg" alt="Image description" width="564" height="752"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What do you see on your phone screen? You see yourself holding your phone, but also another image of yourself holding your phone inside the mirror. And inside that image, there is another image of yourself holding your phone inside another mirror. And so on, infinitely.&lt;/p&gt;

&lt;p&gt;This is like recursion. Each image of yourself holding your phone is like a recursive call to a function that takes a picture of yourself holding your phone. The first image is like the original call, and each subsequent image is like a smaller or simpler input.&lt;/p&gt;

&lt;p&gt;But where is the base case? Well, there isn't one in this analogy. That's why you see an infinite sequence of images. In reality, however, there are some factors that limit the recursion, such as the size of your phone screen, the resolution of your camera, or the distance between you and the mirror.&lt;/p&gt;

&lt;p&gt;These factors act as stopping conditions for the recursion. They prevent it from going on forever and make it possible to get a final result.&lt;/p&gt;

&lt;p&gt;The moral of this analogy is that recursion can be fun and fascinating, but also tricky and dangerous. You need to be careful when using it!&lt;/p&gt;

&lt;p&gt;Hope you found this article helpful, 👏👏👏.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Thank you for reading!&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>recursion</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
