<?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: Yoges</title>
    <description>The latest articles on DEV Community by Yoges (@yogesnsamy).</description>
    <link>https://dev.to/yogesnsamy</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%2F151197%2F9196bb55-66bc-4b40-a9a0-93620e1374db.jpeg</url>
      <title>DEV Community: Yoges</title>
      <link>https://dev.to/yogesnsamy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yogesnsamy"/>
    <language>en</language>
    <item>
      <title>How to run PostgreSQL and pgAdmin on Docker?</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Fri, 19 Apr 2024 11:53:56 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/how-to-run-postgresql-and-pgadmin-on-docker-2glg</link>
      <guid>https://dev.to/yogesnsamy/how-to-run-postgresql-and-pgadmin-on-docker-2glg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Table of content:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prerequisite&lt;/li&gt;
&lt;li&gt;Setting up the Docker network&lt;/li&gt;
&lt;li&gt;Setting up the PostgreSQL container&lt;/li&gt;
&lt;li&gt;Setting up the pgAdmin container&lt;/li&gt;
&lt;li&gt;Creating a new database on the containerized PostgreSQL&lt;/li&gt;
&lt;li&gt;Accessing the new database on the containerized pgAdmin&lt;/li&gt;
&lt;li&gt;Tips&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="prerequisite"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Prerequisite
&lt;/h3&gt;

&lt;p&gt;Install all Docker tools for your computer from &lt;a href="https://docs.docker.com/get-docker" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="docker-network"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting up the Docker network
&lt;/h3&gt;

&lt;p&gt;We're going to install PostgreSQL and pgAdmin on separate containers. &lt;br&gt;
To enable these two containers to communicate with each other, they need to be available on the same Docker network. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create the Docker network with the following command on the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network create my-network
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;This command creates a new Docker network with the following options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;create my-network&lt;/code&gt;: sets the name of the network to "my-network", this can bet set it to any name preferred&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="postgresql-container"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting up the PostgreSQL container
&lt;/h3&gt;

&lt;p&gt;Two steps are involved here. Please perform the following from the terminal. &lt;/p&gt;

&lt;p&gt;&lt;a id="pull-postgres-image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Pull the latest PostgreSQL Docker image from the &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;Docker Hub repository&lt;/a&gt; with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull postgres
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Wait for the image to be downloaded. Docker will automatically download the necessary layers and dependencies.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Create and run a new container based on the image just pulled with the command:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; my-postgres &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;password &lt;span class="nt"&gt;-network&lt;/span&gt; my-network &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 5432:5432 postgres
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;The above command starts a new PostgreSQL container with the following options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--name my-postgres&lt;/code&gt;: sets the name of the container to "my-postgres", we can set it to any name we like.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-e POSTGRES_PASSWORD=password&lt;/code&gt;: sets the password for the default "postgres" user to "password".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-network my-network&lt;/code&gt;: attaches the Docker network to "my-network" which was the network we created earlier.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d&lt;/code&gt;: runs the container in detached mode (in the background).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p 5432:5432&lt;/code&gt;: maps the container's port 5432 to the host's port 5432, allowing access to the PostgreSQL server from outside the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;postgres&lt;/code&gt;: specifies the Docker image to use to create the container; in our case it's the image we pulled from the Docker Hub in step 1. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="pgadmin-container"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting up the pgAdmin container
&lt;/h3&gt;

&lt;p&gt;This involves two steps as well.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Pull the official Docker distribution of pgAdmin 4 from the &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;Docker Hub repository&lt;/a&gt; with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull dpage/pgadmin4
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Wait for the image to be downloaded. Docker will automatically download the necessary layers and dependencies.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Create and run a new container based on the image just pulled with the command:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; my-pgadmin &lt;span class="nt"&gt;-p&lt;/span&gt; 80:80 &lt;span class="nt"&gt;-v&lt;/span&gt; /path/to/local/directory:/var/lib/pgadmin &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;PGADMIN_DEFAULT_EMAIL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your_email@example.com &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;PGADMIN_DEFAULT_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your_password &lt;span class="nt"&gt;--network&lt;/span&gt; my-network &lt;span class="nt"&gt;-d&lt;/span&gt; dpage/pgadmin4
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;The above command starts a new PostgreSQL container with the following options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--name my-pgadmin&lt;/code&gt;: sets the name of the container to "my-pgadmin", we can set it to any name we like.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p 80:80&lt;/code&gt;: maps port 80 of the container to port 80 of the host machine. This allows accessing pgAdmin via a web browser.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-v /path/to/local/directory:/var/lib/pgadmin&lt;/code&gt;: mounts a local directory from your host machine (/path/to/local/directory) to the /var/lib/pgadmin directory inside the container. Replace /path/to/local/directory with the actual path on your host machine where you want to store the pgAdmin data. By mounting a volume, the pgAdmin data will be persisted outside the container, on your host machine. Even if you stop and remove the container, the data will remain intact in the specified local directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-e PGADMIN_DEFAULT_EMAIL=your_email@example.com&lt;/code&gt;: sets the default email for logging into pgAdmin. Replace &lt;a href="mailto:your_email@example.com"&gt;your_email@example.com&lt;/a&gt; with your desired email address.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-e PGADMIN_DEFAULT_PASSWORD=your_password&lt;/code&gt;: sets the default password for logging into pgAdmin. Replace your_password with your desired password.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-network my-network&lt;/code&gt;: attaches the Docker network to "my-network" which was the network we created earlier.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d&lt;/code&gt;: runs the container in detached mode, meaning it runs in the background.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dpage/pgadmin4&lt;/code&gt;: specifies the Docker image to use for creating the container.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="postgresql-create-new-db"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating a new database on the containerized PostgreSQL
&lt;/h3&gt;

&lt;p&gt;Now that we have the PostgreSQL container set up and running, let's create a new database on its server. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Ensure the PostgreSQL container is running:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;open a terminal or command prompt.&lt;/li&gt;
&lt;li&gt;run the following command to list the running Docker containers and then verify that your PostgreSQL container is listed with the status running:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open a shell inside the PostgreSQL container with the following command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;replace  with the actual name or ID of the PostgreSQL container (in our case it'll be my-postgres).&lt;/li&gt;
&lt;li&gt;this command opens an interactive shell session inside the container.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;container_name_or_id&amp;gt; bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inside the container's shell, use the psql command to connect to the PostgreSQL database with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Next create a new database using the following SQL command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;replace  with the desired name for the new database
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="pgadmin-containerized"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing the new database on the containerized pgAdmin
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Ensure the pgAdmin container is running:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;open a terminal or command prompt.&lt;/li&gt;
&lt;li&gt;run the following command to list the running Docker containers &amp;amp; verify the pgAdmin container is listed and running.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access pgAdmin in the web browser at &lt;a href="http://localhost" rel="noopener noreferrer"&gt;http://localhost&lt;/a&gt; and enter the username and password used during set up. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In pgAdmin, create a new server connection with the following details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Host name/address&lt;/code&gt;: my-postgres (the name of the PostgreSQL container)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Port&lt;/code&gt;: 5432 (the default PostgreSQL port inside the container)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Username&lt;/code&gt;: postgres (the default PostgreSQL username)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Password&lt;/code&gt;: The password specified when running the PostgreSQL container&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now you should be able to connect to the PostgreSQL container from the pgAdmin container using the specified server connection. Both containers are communicating through the "my-network" network.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt; &lt;br&gt;
&lt;a id="tips"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;If we already having PostgreSQL running locally, it's very likely to have been configured to run on the default port 5432.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To prevent conflict, map the PostgreSQL container to a different port.&lt;/li&gt;
&lt;li&gt;In the example below the PostgreSQL container is still using port 5432 internally, but it's mapped to port 5433 on the host machine
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; my-postgres &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;password &lt;span class="nt"&gt;-network&lt;/span&gt; my-network &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 5433:5432 postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Instead of accessing pgAdmin at &lt;a href="http://localhost" rel="noopener noreferrer"&gt;http://localhost&lt;/a&gt;, we can map it to a specific URL like &lt;a href="http://local.pgadmin" rel="noopener noreferrer"&gt;http://local.pgadmin&lt;/a&gt; for a more user-friendly access.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We accomplish this by using a reverse proxy server like Nginx on the host machine. I'll write about this in the future. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What if we have to programatically access the containerized database from the code?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nothing changes here, we access it like how we access a local database, for e.g at:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;postgres://postgres:password@localhost:5433/&amp;lt;the_containerized_database_name&amp;gt;?sslmode&lt;span class="o"&gt;=&lt;/span&gt;prefer
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>docker</category>
      <category>postgres</category>
      <category>pgadmin</category>
      <category>container</category>
    </item>
    <item>
      <title>8 websites to improve your CSS-related productivity</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Sat, 20 Feb 2021 14:18:07 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/8-awesome-websites-to-improve-your-css-related-productivity-4b24</link>
      <guid>https://dev.to/yogesnsamy/8-awesome-websites-to-improve-your-css-related-productivity-4b24</guid>
      <description>&lt;h1&gt;
  
  
  To work faster
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://flexbox.help/" rel="noopener noreferrer"&gt;Test CSS Flexbox Rules&lt;/a&gt; - to quickly generate the layouts you need.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://imagecompressor.com/" rel="noopener noreferrer"&gt;Optimizilla&lt;/a&gt; - Compressing is &lt;em&gt;&lt;a href="https://www.techrepublic.com/index.php/resource-library/whitepapers/vhdl-simulation-of-image-compression-using-lbg/" rel="noopener noreferrer"&gt;concerned with minimizing the number of bits required to represent an image&lt;/a&gt;&lt;/em&gt;. Compressing reduces an image size without much compromising its quality. Smaller size means faster loading time which equals happier users. &lt;br&gt;
&lt;a href="https://media2.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%2Fb32n11n1ofrx28qv29m2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fb32n11n1ofrx28qv29m2.png" alt="Screenshot 2021-02-20 at 7.54.30 PM" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://9elements.com/bem-cheat-sheet/#card+i" rel="noopener noreferrer"&gt;BEM naming cheatsheet&lt;/a&gt; - Ever ran out of names for your CSS elements? Don't go naming them like below; use BEM instead! Visit the website to learn a good convention to consider. &lt;br&gt;
&lt;a href="https://media2.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%2Fe6jqwfowtewsoz1txb5i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe6jqwfowtewsoz1txb5i.png" alt="Screenshot 2021-02-20 at 10.08.28 PM" width="506" height="462"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://appletree.or.kr/quick_reference_cards/CSS/CSS%20selectors%20cheatsheet.pdf" rel="noopener noreferrer"&gt;CSS selectors cheatsheet&lt;/a&gt; - Sometimes we have to modify a deep-nested element or target a few elements at the same time; this reference will come in handy at these times. &lt;br&gt;
&lt;a href="https://media2.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%2Fyki1g1acn6e736763q16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyki1g1acn6e736763q16.png" alt="Screenshot 2021-02-22 at 5.47.05 PM" width="800" height="548"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;  &lt;br&gt;
  &lt;/p&gt;

&lt;h1&gt;
  
  
  To play and learn
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://cssgridgarden.com/" rel="noopener noreferrer"&gt;Grid Garden&lt;/a&gt; - a fun way to learn CSS grid by playing a cute game&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://flexboxfroggy.com/" rel="noopener noreferrer"&gt;Flexbox Froggy&lt;/a&gt; - while you're at it, why not learn flexbox by playing a game too. Fun!
&lt;img src="https://media2.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%2Fmqp3za9ak613c5cp63wt.png" alt="Screenshot 2021-02-20 at 10.11.35 PM" width="800" height="341"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;  &lt;br&gt;
  &lt;/p&gt;

&lt;h1&gt;
  
  
  For your reading pleasure
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://bradfrost.com/blog/post/7-habits-of-highly-effective-media-queries/" rel="noopener noreferrer"&gt;7 habits of highly effective media queries&lt;/a&gt;&lt;a href="https://bradfrost.com/blog/post/7-habits-of-highly-effective-media-queries/" rel="noopener noreferrer"&gt;&lt;/a&gt; - this informative article is linked to many other resources to strengthen your understanding on building responsive apps.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/news/the-100-correct-way-to-do-css-breakpoints-88d6a5ba1862" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/the-100-correct-way-to-do-css-breakpoints-88d6a5ba1862&lt;/a&gt; - this writeup has a lot of tips on working with breakpoints. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>css</category>
    </item>
    <item>
      <title>How to Learn React for Newbies</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Sat, 10 Oct 2020 02:23:23 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/how-to-learn-react-for-newbies-36b4</link>
      <guid>https://dev.to/yogesnsamy/how-to-learn-react-for-newbies-36b4</guid>
      <description>&lt;p&gt;And by newbies, I mean those with minimal to no experience coding in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; is a JavaScript library for building user interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite: JavaScript
&lt;/h2&gt;

&lt;p&gt;As React is built on top of JavaScript(JS), it's crucial to understand the basics of it before learning React.&lt;/p&gt;

&lt;p&gt;Also good to have is a decent knowledge about HTML and CSS. &lt;/p&gt;

&lt;h2&gt;
  
  
  How much JS to Know?
&lt;/h2&gt;

&lt;p&gt;JS has many versions and the one that's most relevant to us is JS ES5 and beyond. &lt;/p&gt;

&lt;p&gt;Here's a nice write-up on the important JS concepts to take note of before learning React by LogRocket:&lt;br&gt;
&lt;a href="https://blog.logrocket.com/javascript-concepts-before-learning-react/" rel="noopener noreferrer"&gt;JavaScript concepts to master before learning React&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Do cross-reference the article against the following two repos on GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/lukehoban/es6features" rel="noopener noreferrer"&gt;ECMAScript 6&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/leonardomso/33-js-concepts" rel="noopener noreferrer"&gt;33 Concepts Every JavaScript Developer Should Know&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you prefer watching video tutorials, I highly encourage you to check out The Net Ninja's &lt;a href="https://www.udemy.com/course/modern-javascript-from-novice-to-ninja" rel="noopener noreferrer"&gt;Modern JavaScript (from Novice to Ninja)&lt;/a&gt; on Udemy.&lt;/p&gt;

&lt;p&gt;I first found him on YouTube while trying to make sense of &lt;a href="https://www.youtube.com/watch?v=sakQbeRjgwg&amp;amp;list=PL4cUxeGkcC9jdm7QX143aMLAqyM-jTZ2x" rel="noopener noreferrer"&gt;OAuth&lt;/a&gt; and I've been a fan since. &lt;a href="https://twitter.com/thenetninjauk?lang=en" rel="noopener noreferrer"&gt;The Net Ninja&lt;/a&gt; has a way of making even the hardest of concepts sound simple. &lt;/p&gt;

&lt;p&gt;Not sure about the purchase? Check out the preview of &lt;a href="https://www.youtube.com/watch?v=iWOYAxlnaww&amp;amp;list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc" rel="noopener noreferrer"&gt;his course on Youtube&lt;/a&gt; first. &lt;/p&gt;

&lt;p&gt;Once you’re comfortable with the concepts, you can begin learning React (yeay!)&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn React By Watching Videos
&lt;/h2&gt;

&lt;p&gt;Colt Steele's &lt;a href="https://www.udemy.com/course/modern-react-bootcamp/learn/lecture/14376118#overview" rel="noopener noreferrer"&gt;Modern React Bootcamp&lt;/a&gt; was the one where all things React finally started to make sense to me. &lt;/p&gt;

&lt;p&gt;I have a few other React courses in my Udemy account but I had a tough time wrapping my head around the concept of JSX, props, state etc until I found Colt's course! &lt;/p&gt;

&lt;p&gt;Colt's &lt;a href="https://www.udemy.com/course/the-web-developer-bootcamp/" rel="noopener noreferrer"&gt;The Web Developer Bootcamp&lt;/a&gt; is my favourite course ever so I didn't think twice before purchasing his React course when it was launched. Needless to say I was superbly pleased and grateful. :)&lt;/p&gt;

&lt;p&gt;If you're pressed for time, you don't have to complete the whole course. My recommendation is to work on the following sections: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Section 1 - 15&lt;/li&gt;
&lt;li&gt;Section 17-23&lt;/li&gt;
&lt;li&gt;Section 32 - 33&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learn React By Reading
&lt;/h2&gt;

&lt;p&gt;Alternatively, if you prefer reading over watching videos, do checkout this awesome FREE course by the &lt;a href="https://www.helsinki.fi/fi" rel="noopener noreferrer"&gt;University of Helsinki&lt;/a&gt; called &lt;a href="https://fullstackopen.com/en#course-contents" rel="noopener noreferrer"&gt;Deep Dive Into Modern Web Development&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The following sections will be most relevant for our purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 0 to 2&lt;/li&gt;
&lt;li&gt;Part 7&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do take note that this course is more fast-paced than Colt's course. I had good understanding of React concepts before I started on this course. &lt;/p&gt;

&lt;p&gt;What I liked best of this course is that it quickly brought me up to speed of React's new feature (at that time) called &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;Hooks&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This course is also available in &lt;a href="https://fullstackopen.com/zh" rel="noopener noreferrer"&gt;Chinese&lt;/a&gt; and &lt;a href="https://fullstackopen.com/" rel="noopener noreferrer"&gt;Finnish&lt;/a&gt;/&lt;/p&gt;

&lt;h2&gt;
  
  
  Recording your Learning Journey
&lt;/h2&gt;

&lt;p&gt;As you learn, it'll be a good idea to push the code you write to &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. This will get you familiarized with using git and also serve as a record on what you’re working on.&lt;/p&gt;

&lt;p&gt;Unfamiliar with git? Start here: &lt;a href="https://rogerdudler.github.io/git-guide/" rel="noopener noreferrer"&gt;git - the simple guide&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions?
&lt;/h2&gt;

&lt;p&gt;If you’re stuck while learning, don't forget to look for answers on the courses’ forums.&lt;/p&gt;

&lt;p&gt;Another good place to look for answers is the website &lt;a href="//stackoverflow.com"&gt;stackoverflow&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you do post a question on forums, I suggest that you do include the following information so that readers are more inclined to respond to your query: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What your issue is&lt;/li&gt;
&lt;li&gt;What you have done to troubleshoot the issue&lt;/li&gt;
&lt;li&gt;What you don’t understand or what you need assistance with&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s all for now. Have fun learning!&lt;/p&gt;

</description>
      <category>react</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Nevertheless, Yoges Coded</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Sat, 07 Mar 2020 10:48:33 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/nevertheless-yoges-coded-2opk</link>
      <guid>https://dev.to/yogesnsamy/nevertheless-yoges-coded-2opk</guid>
      <description>&lt;h2&gt;
  
  
  The beginning
&lt;/h2&gt;

&lt;p&gt;I've always found technology exciting and cool. Being born in the 80s, I was there when things around me changed significantly thanks to the internet. I tried coding before I entered uni - got myself a C++ book and tried the samples which never actually worked because I didn't even know what a compiler was.&lt;/p&gt;

&lt;p&gt;Nevertheless I coded. &lt;/p&gt;

&lt;h2&gt;
  
  
  The next phase
&lt;/h2&gt;

&lt;p&gt;In uni I learnt Pascal, C &amp;amp; Java and majored in Software Engineering. I graduated with a degree in Computer Science and started as a software developer in a local software development house. I learnt a lot in this company - coding (in Lotus Domino, RPG and BHT8000) and visiting clients across the neighboring country to work on implementations.&lt;/p&gt;

&lt;h2&gt;
  
  
  The screw up
&lt;/h2&gt;

&lt;p&gt;It was during one of these business trips that I screwed up big time working on an AS/400 ERP system. I overwrote a production library instead of testing, OMG!!! It took a team of four many days of overtime and weekend work to clean up the mess I made. It made me overcautious and phobic of ever visiting a client place again. &lt;/p&gt;

&lt;p&gt;Nevertheless I coded - thanks to my manager's support and encouragement. &lt;/p&gt;

&lt;h2&gt;
  
  
  The move
&lt;/h2&gt;

&lt;p&gt;Seven years later, I was still coding - as a mother with a newborn now. I said yes when a recruiter called with a great opportunity at a company I dreamt of retiring in. It wasn't a developer role but there was a lot of learning opportunities and hey it was my dream company.&lt;/p&gt;

&lt;p&gt;The job required me to learn hardware stuff and none of coding. &lt;/p&gt;

&lt;p&gt;Nevertheless I coded - building mini apps for the team to improve things around me. &lt;/p&gt;

&lt;h2&gt;
  
  
  Next phase of life
&lt;/h2&gt;

&lt;p&gt;Five years down the road, technology had evolved so much thanks to cloud; and I was now a mom of three (a boy and a pair of boys :)) who yearned to spend quality time with the kids instead of spending so much time in the traffic traveling to and fro work. &lt;/p&gt;

&lt;h2&gt;
  
  
  The plan?
&lt;/h2&gt;

&lt;p&gt;It was to start learning web development. I figured having these skills, I'd be able to get a job as a coder that would give me a lot of flexibility to work remotely. And as it was, I loved to code so getting paid to do what I love was just perfect.&lt;/p&gt;

&lt;p&gt;It wasn't easy trying to catch up on things. &lt;/p&gt;

&lt;p&gt;Nevertheless, I coded. &lt;/p&gt;

&lt;h2&gt;
  
  
  Learning to code again
&lt;/h2&gt;

&lt;p&gt;Udemy helped me a lot when I started on this journey in 2018. &lt;/p&gt;

&lt;p&gt;While learning, I participated in my employer's nationwide appmakers' challenge and won with my JavaScript prototype; I was beyond thrilled! &lt;br&gt;
Soon after together with a few colleagues, I got the opportunity to mentor final year undergraduates to further develop my idea. &lt;/p&gt;

&lt;h2&gt;
  
  
  The internal job application
&lt;/h2&gt;

&lt;p&gt;These gave me the confidence to apply for an internal job opening for the role of a software developer even though I didn't meet many of their requirements. &lt;/p&gt;

&lt;p&gt;I figured the personal interest that I've demonstrated all the while would compensate. I was wrong and upset for many days to come. &lt;/p&gt;

&lt;p&gt;Nevertheless I coded and started picking up React and Linux skills.&lt;/p&gt;

&lt;h2&gt;
  
  
  The interview
&lt;/h2&gt;

&lt;p&gt;Many months later, magic happened when I came across a post I resonated with on LinkedIn and requested to connect with the poster.&lt;/p&gt;

&lt;p&gt;He kindly reviewed my resume and invited me to an interview session with the CTO. A few days later I got an offer! I didn't expect to get a break so soon and I was very grateful I did. &lt;/p&gt;

&lt;h2&gt;
  
  
  Back to coding
&lt;/h2&gt;

&lt;p&gt;I've been on the job for two months now. It has not exactly been an easy journey since I joined - there's so much to learn and things are not really like how they were on tutorials. I've had many sleepless days trying to catch up on React, GraphQL, AWS and other related technologies. &lt;/p&gt;

&lt;p&gt;Still I coded - even when deadlines loomed and I had five hours of sleep a day, I continued and tried not to give up. My teammates helped a lot along the way explaining stuff I didn't understand or get. &lt;/p&gt;

&lt;h2&gt;
  
  
  The ending?
&lt;/h2&gt;

&lt;p&gt;Compared to the days I thought I'd never get through, things are looking more positive now as I understand the work flow and get more familiar with how all the pieces fit together. &lt;/p&gt;

&lt;p&gt;Does it mean things won't get challenging anymore? They certainly will as technology evolves and there's still so much for me to catch up on. But positivity and determination will go a long way in achieving what our heart desires.&lt;/p&gt;

&lt;p&gt;I believe we'll do well to utilize the support offered by the internet - on communities like dev.to, twitter's #100daysofCode and even stackoverflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you #100DaysOfCode &amp;amp; #CodeNewbie
&lt;/h2&gt;

&lt;p&gt;Throughout the journey as I got back to coding, the one constant support I had was on Twitter. Using the hashtags #100DaysOfCode &amp;amp; #CodeNewbie I was able to connect to many like minded people who were always generous in their support and encouragement. &lt;/p&gt;

</description>
      <category>wecoded</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to use the `reduce` Method in JavaScript (and React)</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Wed, 20 Nov 2019 10:20:27 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/how-to-use-the-reduce-method-in-javascript-and-react-5dhl</link>
      <guid>https://dev.to/yogesnsamy/how-to-use-the-reduce-method-in-javascript-and-react-5dhl</guid>
      <description>&lt;h1&gt;
  
  
  What is &lt;code&gt;reduce&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;It's an ES5 method in JavaScript like &lt;code&gt;for..each&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; which we can use with arrays.&lt;/p&gt;

&lt;p&gt;The difference is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;as the name suggests it reduces the number of values in an array to one. &lt;/li&gt;
&lt;li&gt;we have access to the array's previous value apart from its current value and index.&lt;/li&gt;
&lt;li&gt;we will send the accumulator's start value to the callback function; so when we first start previous value will be the same as the accumulator's start value&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  A Simple Example of Using &lt;code&gt;reduce&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Let's look at a simple example that uses &lt;code&gt;reduce&lt;/code&gt; to count the total of an array.&lt;br&gt;
Imagine you have an array: &lt;code&gt;[98,45,33,47,100,80]&lt;/code&gt;&lt;br&gt;
We can write the following code to use the &lt;code&gt;reduce&lt;/code&gt; method to sum up the values in this array:&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;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;80&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;totalScores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scores&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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previousScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;previousScore&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;currentScore&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;totalScores&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns 403&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens in the code is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;we call the &lt;code&gt;reduce&lt;/code&gt; method on the array &lt;code&gt;scores&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;the method has access to the array's &lt;code&gt;previous&lt;/code&gt; value, &lt;code&gt;current&lt;/code&gt; value and &lt;code&gt;index&lt;/code&gt;. 
*We don't use &lt;code&gt;index&lt;/code&gt; in this example.&lt;/li&gt;
&lt;li&gt;we send zero as the &lt;code&gt;accumulator&lt;/code&gt;'s initial value. &lt;/li&gt;
&lt;li&gt;in our example when the method first runs (where &lt;code&gt;currentScore&lt;/code&gt; is 98), &lt;code&gt;previousScore&lt;/code&gt; assumes the value of zero as sent to the callback function.&lt;/li&gt;
&lt;li&gt;the result of &lt;code&gt;totalScores&lt;/code&gt; is 403.&lt;/li&gt;
&lt;li&gt;if we change the initial value of the &lt;code&gt;accumulator&lt;/code&gt; to 100, the value of &lt;code&gt;totalScores&lt;/code&gt; then changes to 503.
&lt;/li&gt;
&lt;/ol&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;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;80&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;totalScores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scores&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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previousScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;previousScore&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;currentScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="mi"&gt;100&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;totalScores&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns 503&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Using &lt;code&gt;reduce&lt;/code&gt; in React
&lt;/h1&gt;

&lt;p&gt;Imagine you have the following data structure in the &lt;code&gt;App&lt;/code&gt; component:&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;course&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Half Stack application development&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;parts&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;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fundamentals of React&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exercises&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Using props to pass data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exercises&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;State of a component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exercises&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&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="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;To display the total number of exercises in in the &lt;code&gt;Total&lt;/code&gt; component:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;from &lt;code&gt;App&lt;/code&gt; send &lt;code&gt;parts&lt;/code&gt; as a prop to &lt;code&gt;Total&lt;/code&gt;:&lt;/li&gt;
&lt;li&gt;in &lt;code&gt;Total&lt;/code&gt;, call the &lt;code&gt;reduce&lt;/code&gt; method on &lt;code&gt;parts&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parts&lt;/code&gt; contains multiple values &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;exercises&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;so we explicitly specify &lt;code&gt;exercises&lt;/code&gt; as the value we want to use in the calculation.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;App.js&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Total&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./components/Total&lt;/span&gt;&lt;span class="dl"&gt;"&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;App&lt;/span&gt; &lt;span class="o"&gt;=&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Half Stack application development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;parts&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;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fundamentals of React&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exercises&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Using props to pass data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exercises&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;State of a component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exercises&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&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="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="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Total&lt;/span&gt; &lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&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;ul&gt;
&lt;li&gt;
&lt;code&gt;Total.js&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&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;Total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parts&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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevValue&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;prevValue&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="nx"&gt;exercises&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="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Totalzzz&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Result:
&lt;img src="https://media2.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%2F7qh54uuo3q707tircfc6.jpeg" alt="Alt Text" width="437" height="125"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es5</category>
      <category>reduce</category>
    </item>
    <item>
      <title>How to Add Custom CSS &amp; JavaScript Files to an ExpressJS App</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Sat, 12 Oct 2019 09:16:58 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/how-to-add-custom-css-javascript-files-to-an-expressjs-app-48cp</link>
      <guid>https://dev.to/yogesnsamy/how-to-add-custom-css-javascript-files-to-an-expressjs-app-48cp</guid>
      <description>&lt;p&gt;This tutorial assumes the use of &lt;a href="https://ejs.co/" rel="noopener noreferrer"&gt;EJS&lt;/a&gt; as the view template engine of your Express app. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Generate an Express App Skeleton
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/yogesnsamy/how-to-quickly-generate-an-express-app-skeleton-and-then-edit-it-5b00"&gt;The easiest way to create an Express app is by using the express-generator&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Download CSS and JavaScript Files
&lt;/h3&gt;

&lt;p&gt;In this example, we're going to use &lt;a href="https://materializecss.com/" rel="noopener noreferrer"&gt;MaterializeCSS&lt;/a&gt; to beautify our app. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://materializecss.com/getting-started.html" rel="noopener noreferrer"&gt;MaterializeCSS's website&lt;/a&gt; and download the compressed CSS and JavaScript files. 
&lt;img src="https://media2.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%2F3xybkne2sfq650gl0sf4.jpg" alt="Alt Text" width="773" height="395"&gt;
&lt;/li&gt;
&lt;li&gt;Once downloaded, extract the files into the folder &lt;em&gt;public&lt;/em&gt; in your app.&lt;/li&gt;
&lt;li&gt;Take note to place CSS and JavaScript files into different folders inside the &lt;em&gt;public&lt;/em&gt; folder.&lt;/li&gt;
&lt;li&gt;The file 'materialize.css' will go into folder &lt;em&gt;public/stylesheets&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;The file 'materialize.js' will go into folder &lt;em&gt;public/javascripts&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 3: Create &lt;em&gt;partials&lt;/em&gt; files
&lt;/h3&gt;

&lt;p&gt;We'll create a &lt;em&gt;header&lt;/em&gt; and a &lt;em&gt;footer&lt;/em&gt; file inside the folder &lt;em&gt;partials&lt;/em&gt;. These files will be linked our EJS files. We create partial files to easily link external files to EJS files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a folder named &lt;em&gt;partials&lt;/em&gt; inside folder &lt;em&gt;views&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Create a new file called &lt;em&gt;header.ejs&lt;/em&gt; inside folder &lt;em&gt;partials&lt;/em&gt; with the following content:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nx"&gt;DOCTYPE&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf-8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;equiv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X-UA-Compatible&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IE=edge&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;viewport&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;width=device-width, initial-scale=1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;iVMS&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stylesheet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/stylesheets/materialize.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a new file called &lt;em&gt;footer.ejs&lt;/em&gt; inside folder &lt;em&gt;partials&lt;/em&gt; with the following content:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;         &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;      &lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text/javascript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/javascripts/materialize.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Your folder structure will now look like the following:
&lt;img src="https://media2.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%2Fmank0zo62ediy90c7occ.jpg" alt="Alt Text" width="279" height="428"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Link &lt;em&gt;partials&lt;/em&gt; files to EJS files.
&lt;/h3&gt;

&lt;p&gt;Now that we have specified custom CSS and JavaScript files to be used in our app, let's see how it looks like on the app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace the content of the file &lt;em&gt;index.ejs&lt;/em&gt; with the following:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="nx"&gt;include&lt;/span&gt; &lt;span class="nx"&gt;partials&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Welcome&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="nx"&gt;include&lt;/span&gt; &lt;span class="nx"&gt;partials&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;footer&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: New Styling is Now Applied to Our App
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Before:&lt;br&gt;
&lt;a href="https://media2.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%2Fsytyx99u9sroblthpn3c.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsytyx99u9sroblthpn3c.jpg" alt="Alt Text" width="357" height="218"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After - MaterializeCSS styling is now applied to our app!&lt;br&gt;
&lt;a href="https://media2.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%2Fpwpm0lp04iiuwc6yzt10.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpwpm0lp04iiuwc6yzt10.jpg" alt="Alt Text" width="301" height="189"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How Does This Work?
&lt;/h3&gt;

&lt;p&gt;The code works because as we generated the Express app skeleton, some settings have been automatically added for us. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the file &lt;em&gt;app.js&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;You'll notice the use of the built-in middleware &lt;em&gt;express.static&lt;/em&gt; on line 20 of the code.&lt;/li&gt;
&lt;li&gt;This is the reason why we store our CSS and JavaScript files inside the folder &lt;em&gt;public&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;It's also the reason why we don't have to explicitly specify the name &lt;em&gt;public&lt;/em&gt; in our path. 
&lt;img src="https://media2.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%2Fiwl0six66pybjr3v4o8p.jpg" alt="Alt Text" width="654" height="108"&gt;
More info about this &lt;a href="https://expressjs.com/en/starter/static-files.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How To Quickly Generate An Express App Skeleton And Then Edit It</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Mon, 23 Sep 2019 02:00:54 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/how-to-quickly-generate-an-express-app-skeleton-and-then-edit-it-5b00</link>
      <guid>https://dev.to/yogesnsamy/how-to-quickly-generate-an-express-app-skeleton-and-then-edit-it-5b00</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First you must install the express-generator by typing:&lt;br&gt;
&lt;strong&gt;npm install -g express-generator&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next run the following command to create an express app with the &lt;em&gt;ejs&lt;/em&gt; engine:&lt;br&gt;
&lt;strong&gt;express --view=ejs kikucare&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;kikucare&lt;/em&gt; is the name of the app we're creating. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fz8tm80b5kkvjdnsnstq0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fz8tm80b5kkvjdnsnstq0.jpg" alt="Alt Text" width="449" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go into the newly created app folder by typing:&lt;br&gt;
&lt;strong&gt;cd kikucare/&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install all dependencies by typing:&lt;br&gt;
&lt;strong&gt;npm install&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next start the app by typing the command:&lt;br&gt;
&lt;strong&gt;DEBUG=kikucare:* npm start&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can now view the app on the browser by going to the address &lt;strong&gt;&lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You'll see the following:&lt;br&gt;
&lt;a href="https://media2.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%2Fkdi9uqc1r8fecyqk61rf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkdi9uqc1r8fecyqk61rf.jpg" alt="Alt Text" width="408" height="276"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Let's make a simple change to what's displayed on the browser!
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We'll edit the file &lt;strong&gt;index.js&lt;/strong&gt; from the folder &lt;strong&gt;routes&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media2.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%2Favoj8fz0sdv8ojwxbsdp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Favoj8fz0sdv8ojwxbsdp.jpg" alt="Alt Text" width="297" height="302"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify line number 6 by replacing the &lt;em&gt;title&lt;/em&gt; from 'Express' to 'Kikucare'&lt;br&gt;
&lt;a href="https://media2.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%2F5nzyqfcpqpt9gfxbwxlt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5nzyqfcpqpt9gfxbwxlt.jpg" alt="Alt Text" width="500" height="273"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Output:&lt;br&gt;
&lt;a href="https://media2.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%2Fgw2iprm0cgy1x0n81juo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgw2iprm0cgy1x0n81juo.jpg" alt="Alt Text" width="406" height="267"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>express</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Fetch API 101</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Mon, 10 Jun 2019 16:36:40 +0000</pubDate>
      <link>https://dev.to/yogesnsamy/fetch-api-101-4mi9</link>
      <guid>https://dev.to/yogesnsamy/fetch-api-101-4mi9</guid>
      <description>&lt;p&gt;&lt;u&gt;Credit&lt;/u&gt;: This sharing is based on my learning from  the super awesome &lt;a href="https://www.udemy.com/modern-javascript-from-novice-to-ninja/"&gt;The Net Ninja's JavaScript Course on Udemy&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pre-requisite&lt;/u&gt;: Some (or more) good knowledge of &lt;a href="https://scotch.io/tutorials/javascript-promises-for-dummies"&gt;&lt;em&gt;promises&lt;/em&gt; is necessary to understand &lt;em&gt;fetch&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;What is &lt;em&gt;fetch&lt;/em&gt;?&lt;/h1&gt;

&lt;p&gt;Simply put it's the modern way of getting data/resources from a server. &lt;em&gt;fetch&lt;/em&gt; is supported by &lt;em&gt;promises&lt;/em&gt; under the hood.&lt;br&gt;
It replaces the use of &lt;a href="https://www.w3schools.com/xml/xml_http.asp"&gt;XMLHttpRequest in making asynchronous calls to networks. &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Due to its newness, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"&gt;&lt;em&gt;fetch&lt;/em&gt; doesn't work on all browsers yet.&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Calling &lt;em&gt;fetch&lt;/em&gt;
&lt;/h1&gt;

&lt;p&gt;To use &lt;em&gt;fetch&lt;/em&gt;, simply type &lt;code&gt;fetch()&lt;/code&gt; and use one of the following as its parameter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an API endpoint - for example &lt;em&gt;&lt;code&gt;fetch("https://jsonplaceholder.typicode.com/todos/1");&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;a local resource - for example &lt;em&gt;&lt;code&gt;fetch("todos/vela.json");&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;fetch&lt;/em&gt; returns a promise which either resolves or rejects which we handle using &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So a &lt;em&gt;fetch&lt;/em&gt; call would look something like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise resolved, do something with result&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise rejected, handle the error&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;Accessing the &lt;em&gt;fetch&lt;/em&gt; response&lt;/h1&gt;

&lt;p&gt;When a promise resolves, &lt;strong&gt;we don't have access to the data we want yet&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;For example, let's run the following code that will randomly retrieve a piece of advice each time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.adviceslip.com/advice&lt;/span&gt;&lt;span class="dl"&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise resolved, do something with result&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Resolved: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&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;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise rejected, handle the error&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rejected: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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;The code returns a &lt;em&gt;response&lt;/em&gt; object. We will now have to call the &lt;em&gt;json&lt;/em&gt; method available on the &lt;em&gt;response&lt;/em&gt; object to access the returned data. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Iqa-eDJ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4b3owty0pedcwe7b8f3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Iqa-eDJ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4b3owty0pedcwe7b8f3c.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Calling the &lt;em&gt;json&lt;/em&gt; Method on the &lt;em&gt;Response&lt;/em&gt; Object&lt;/h1&gt;

&lt;p&gt;As shown above, &lt;em&gt;json&lt;/em&gt; is a method on the &lt;em&gt;response&lt;/em&gt; object (which we can see by expanding the &lt;em&gt;&lt;strong&gt;proto&lt;/strong&gt;&lt;/em&gt; key). &lt;/p&gt;

&lt;p&gt;We need to call the &lt;em&gt;json&lt;/em&gt; method on the &lt;em&gt;response&lt;/em&gt; object to get the data we need. &lt;/p&gt;

&lt;p&gt;When the &lt;em&gt;json&lt;/em&gt; method is called, another promise will be returned which can either be resolved or rejected. So we need to chain the first call to another to manipulate the resulting data.&lt;/p&gt;

&lt;p&gt;The way to do this is as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.adviceslip.com/advice&lt;/span&gt;&lt;span class="dl"&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise resolved, do something with result&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Resolved: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;//new code&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="c1"&gt;//new code&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise rejected, handle the error&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rejected: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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;Output:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qnxmS85O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6nii7d4f392hjxf8v2c1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qnxmS85O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6nii7d4f392hjxf8v2c1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is ladies and gentlemen, how &lt;em&gt;fetch&lt;/em&gt; works in a nutshell!&lt;/p&gt;

&lt;h1&gt;Three Steps to Remember While Working With &lt;em&gt;fetch&lt;/em&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;fetch("xyz");&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;response.json()&lt;/code&gt; on the response&lt;/li&gt;
&lt;li&gt;Do something with the data&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;Note on the &lt;em&gt;Response&lt;/em&gt;'s HTTP Status Code&lt;/h1&gt;

&lt;p&gt;Take note that &lt;strong&gt;&lt;em&gt;fetch&lt;/em&gt; doesn't fail even when we call an incorrect end-point/resource&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;For example, calling a non-existent route like &lt;em&gt;&lt;a href="https://api.adviceslip.com/"&gt;https://api.adviceslip.com/&lt;/a&gt;&lt;strong&gt;advicexx&lt;/strong&gt;&lt;/em&gt; won't make the execution jump to the &lt;em&gt;catch&lt;/em&gt; block! A &lt;em&gt;resolve&lt;/em&gt; is still returned in this case but with the HTTP response code of &lt;strong&gt;404&lt;/strong&gt; (instead of &lt;strong&gt;200&lt;/strong&gt;).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X-Oy_k8c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/nrq2r9ocd07mr5wye0eb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X-Oy_k8c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/nrq2r9ocd07mr5wye0eb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So it's a good idea to check the &lt;em&gt;response&lt;/em&gt;'s HTTP status code prior to calling &lt;em&gt;json&lt;/em&gt; on it. For example using the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.adviceslip.com/advice&amp;lt;strong&amp;gt;xx&amp;lt;/strong&amp;gt;&lt;/span&gt;&lt;span class="dl"&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise resolved, do something with result&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Resolved: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//new code&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;200&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Resource not found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="c1"&gt;//new code&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//promise rejected, handle the error&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rejected: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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;Output:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PE-OM5kY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6weyqpvihqxo0eawwqhy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PE-OM5kY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6weyqpvihqxo0eawwqhy.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please check out this entry on Stack Overflow for detailed information about &lt;em&gt;fetch&lt;/em&gt; and catching errors: &lt;a href="https://stackoverflow.com/questions/38235715/fetch-reject-promise-and-catch-the-error-if-status-is-not-ok"&gt;https://stackoverflow.com/questions/38235715/fetch-reject-promise-and-catch-the-error-if-status-is-not-ok&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>promises</category>
      <category>fetch</category>
      <category>api</category>
    </item>
  </channel>
</rss>
