<?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: Jan</title>
    <description>The latest articles on DEV Community by Jan (@janetmutua).</description>
    <link>https://dev.to/janetmutua</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%2F1027391%2Ff1bc1f2a-832e-42dc-ba5e-88964403ee14.png</url>
      <title>DEV Community: Jan</title>
      <link>https://dev.to/janetmutua</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/janetmutua"/>
    <language>en</language>
    <item>
      <title>Understanding Arrow Functions in JavaScript</title>
      <dc:creator>Jan</dc:creator>
      <pubDate>Tue, 26 Aug 2025 13:12:58 +0000</pubDate>
      <link>https://dev.to/janetmutua/understanding-arrow-functions-in-javascript-1ih0</link>
      <guid>https://dev.to/janetmutua/understanding-arrow-functions-in-javascript-1ih0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Arrow functions were introduced in ECMAScript 2015 (ES6) and provide developers with a more concise syntax for writing anonymous function expressions. You can use them for short, one-liner functions instead of declaring a regular function.&lt;/p&gt;

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

&lt;p&gt;For this tutorial, you need a basic understanding of JavaScript concepts, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables, functions, objects, and event handlers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let’s Get a Grasp of the Syntax First
&lt;/h2&gt;

&lt;p&gt;When working with traditional function expressions, you assign an anonymous function to a variable that you can call later in your code. Arrow functions eliminate the need for using the &lt;code&gt;function&lt;/code&gt; keyword in expressions.&lt;/p&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%2F8z0pp2w3502sqwa8pkpu.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%2F8z0pp2w3502sqwa8pkpu.png" alt="Anonymous functions vs. arrow functions" width="800" height="436"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;From the illustration above, the arrow function has no function keyword, curly braces, or return keyword. You eliminate curly braces and the return keyword in single expressions, but you will still need them if you are evaluating more expressions.&lt;/p&gt;

&lt;p&gt;Take a look at how you write arrow functions in different scenarios:&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="c1"&gt;// One parameter; multiple expressions&lt;/span&gt;
&lt;span class="nx"&gt;param&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;expression&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;expression&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="c1"&gt;// Single expression; multiple parameters&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;param2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...,&lt;/span&gt; &lt;span class="nx"&gt;paramN&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;expression&lt;/span&gt;

&lt;span class="c1"&gt;// Single expression; no parameters&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;expression&lt;/span&gt;

&lt;span class="c1"&gt;// Single expression; one parameter&lt;/span&gt;
&lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arrow Functions Use Cases
&lt;/h2&gt;

&lt;p&gt;Arrow functions, being succinct and readable, are useful in various scenarios.&lt;/p&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%2F7n7a8jv7vszr4x1prt9u.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%2F7n7a8jv7vszr4x1prt9u.png" alt="Common use cases of arrow functions" width="800" height="324"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One such case is in declaring single-expression functions, where you can get away with an implicit return.&lt;/p&gt;

&lt;p&gt;Take a look at the differences using an example of an exponential function. You can see the three-line regular function expression transform into only one line using an arrow function.&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="c1"&gt;// Traditional function expression&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;power&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exponent&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;base&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="nx"&gt;exponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Arrow function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;power&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exponent&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;base&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="nx"&gt;exponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrow functions are also useful when working with higher-order functions or array methods like &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, and &lt;code&gt;reduce&lt;/code&gt;. For instance, suppose you want to filter an array based on a certain criterion. How can you implement the logic using an arrow function?&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="c1"&gt;// Given an array of user ages; filter for users younger than 35 years (youth)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userAges&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;56&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;34&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;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&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;youth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userAges&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;age&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;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;35&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;youth&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Output&lt;/span&gt;
&lt;span class="c1"&gt;// [23, 34, 18, 25]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the &lt;code&gt;filter&lt;/code&gt; method, you pass an arrow function with the logic &lt;code&gt;age &amp;lt;=35&lt;/code&gt; that returns a new array with user ages equal to or below 35 years. The arrow function reduces boilerplate in cases where you need to manipulate large datasets.&lt;/p&gt;

&lt;p&gt;Additionally, you can implement arrow functions in callbacks, especially with asynchronous operations or event handlers where preserving the ‘this‘ context is important.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Arrow Functions?
&lt;/h2&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%2F7gfrmfync1qe8f8xdr7i.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%2F7gfrmfync1qe8f8xdr7i.png" alt="Advantages of arrow functions" width="800" height="351"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Apart from the rather obvious benefit of arrow functions being concise and readable, there are other benefits of arrow functions.&lt;/p&gt;

&lt;p&gt;Arrow functions help solve the issue of losing the correct ‘this‘ binding when using traditional functions.&lt;/p&gt;

&lt;p&gt;Arrow functions become beneficial in cases where the ‘this’ context can get lost. A good example is in code that involves callbacks, i.e., when working with event handlers or &lt;code&gt;setTimeout&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What does this actually mean?&lt;/p&gt;

&lt;p&gt;One is that arrow functions avoid a common issue where ‘this‘ points to either a global object or undefined. Two, you no longer have to store ‘this’ in a variable (&lt;code&gt;const self = this&lt;/code&gt;) or use &lt;code&gt;bind()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s take a deeper look at the lexical ‘&lt;code&gt;this&lt;/code&gt;' binding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrow Functions and the Lexical ‘This’ Binding
&lt;/h2&gt;

&lt;p&gt;Arrow functions inherit ‘&lt;code&gt;this&lt;/code&gt;‘ from the surrounding context, like a function or block scope. That means that arrow functions don’t have their own ‘this’ value. Instead, the ‘this’ value is determined by the enclosing (lexical) scope.&lt;/p&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%2F36ijeewdyv8krfnyfnu1.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%2F36ijeewdyv8krfnyfnu1.png" alt="Lexical this binding" width="800" height="436"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To understand the lexical ‘this’ much better, let’s use an example of a function inside a block scope that takes the name of a person and logs it, then, after one second, logs the name again using &lt;code&gt;setTimeout&lt;/code&gt;.&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="c1"&gt;// Example using a regular function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&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;Julia the drummer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;introducePerson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi! My name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// first output&lt;/span&gt;

    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Actually my name is... &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// second output&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&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="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;introducePerson&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// Hi! My name is Julia the drummer&lt;/span&gt;
&lt;span class="c1"&gt;// Actually my name is... undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you call &lt;code&gt;person.introducePerson();&lt;/code&gt; the first output that references ‘&lt;code&gt;this&lt;/code&gt;‘ returns the actual person’s name as expected. But inside &lt;code&gt;setTimeout&lt;/code&gt;, when a new function is called, the correct ‘&lt;code&gt;this&lt;/code&gt;‘ binding is lost, which is why we get undefined.&lt;/p&gt;

&lt;p&gt;Now let’s see what happens when we replace the regular anonymous function in &lt;code&gt;setTimeout&lt;/code&gt; with an arrow function.&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="c1"&gt;// Example using an arrow function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&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;Julia the drummer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;introducePerson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi! My name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&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="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="s2"&gt;`Actually my name is still... &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="mi"&gt;1000&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="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;introducePerson&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// Hi! My name is Julia the drummer&lt;/span&gt;
&lt;span class="c1"&gt;// Actually my name is still... Julia the drummer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, when using the arrow function, you retain the ‘&lt;code&gt;this&lt;/code&gt;‘ value of the original function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations of Arrow Functions
&lt;/h2&gt;

&lt;p&gt;You can’t use arrow functions as constructors. That’s because you cannot override an arrow function with the &lt;code&gt;new&lt;/code&gt; keyword. One reason is that arrow functions don’t have their own ‘&lt;code&gt;this&lt;/code&gt;‘ binding, and two being that they lack the &lt;code&gt;[[Construct]]&lt;/code&gt; internal method needed for instantiation.&lt;/p&gt;

&lt;p&gt;Additionally, you can’t use arrow functions as methods. That’s because arrow functions lack their own ‘&lt;code&gt;this&lt;/code&gt;’ binding along with &lt;code&gt;arguments&lt;/code&gt; or &lt;code&gt;super&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Few Things To Keep in Mind
&lt;/h2&gt;

&lt;p&gt;Arrow functions support destructuring, and also rest, and default parameters. Note that you always have to write these parameters in parentheses. Here’s a simple illustration of how:&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="c1"&gt;// Default parameters&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&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;expression&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Rest parameters&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;r&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;expression&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Destructuring&lt;/span&gt;
&lt;span class="c1"&gt;// Array destructuring&lt;/span&gt;
&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;expression&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Object destructuring&lt;/span&gt;
&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;expression&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also make your arrow function asynchronous by prefixing it with the &lt;code&gt;async&lt;/code&gt; keyword just like this:&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="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;expression&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;In this article, you've learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How arrow functions work, the inner workings of lexical ‘this‘ binding, and various use cases for arrow functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this article has been of help to you.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Keep building! 🌟&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions" rel="noopener noreferrer"&gt;Arrow function expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/arrow-functions-basics" rel="noopener noreferrer"&gt;Arrow functions, the basics&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Fetch API and HTTP requests in JavaScript</title>
      <dc:creator>Jan</dc:creator>
      <pubDate>Thu, 21 Aug 2025 18:50:13 +0000</pubDate>
      <link>https://dev.to/janetmutua/fetch-api-and-http-requests-in-javascript-1oa3</link>
      <guid>https://dev.to/janetmutua/fetch-api-and-http-requests-in-javascript-1oa3</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;A simple guide on using the Fetch API to make network requests in JavaScript. Learn how to use async/await to make your code more readable. See how you can handle errors gracefully to avoid your program crashing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you want a clean and flexible way to handle network requests, then the Fetch API comes in handy. The Fetch API is a modern JavaScript interface for making asynchronous HTTP requests to servers. You use promises to fetch resources from servers asynchronously.&lt;/p&gt;

&lt;p&gt;Promises, as we will see later in this tutorial, help make your code more readable and maintainable as opposed to callback approaches.&lt;/p&gt;

&lt;p&gt;Fetch API replaces older methods like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;XML HttpRequest&lt;/li&gt;
&lt;li&gt;jQuery’s AJAX methods&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;To proceed with this guide, you need a basic understanding of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core JavaScript basics like:

&lt;ul&gt;
&lt;li&gt;Arrow functions&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;li&gt;String manipulation with template literals&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Asynchronous concepts like:

&lt;ul&gt;
&lt;li&gt;Promises (&lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Async/await syntax&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;HTTP and networking basics, such as:

&lt;ul&gt;
&lt;li&gt;HTTP methods (GET and POST)&lt;/li&gt;
&lt;li&gt;Status codes&lt;/li&gt;
&lt;li&gt;Basic API understanding&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;I will provide brief explanations of these concepts whenever necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Fetch API Syntax
&lt;/h2&gt;

&lt;p&gt;Before we dive into the various use cases of the Fetch API, let’s first get a rundown of the syntax.&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="nf"&gt;fetch&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;span class="nf"&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="nx"&gt;response&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;// parses the response body to JSON&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="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;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// logs the data into the console&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;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;error&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="c1"&gt;// catches errors if request fails&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;fetch()&lt;/code&gt; function takes a URL as an argument and sends requests to that URL. The default request is usually a GET request. You can supply an optional second argument as an object to specify a HTTP method, or headers in the case of a POST request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.then()&lt;/code&gt; handles responses when the request is successful. You parse the response body to JSON and later log the data received.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.catch()&lt;/code&gt; catches errors like network issues and invalid responses, in cases where the request fails. However, &lt;code&gt;.catch()&lt;/code&gt; doesn’t throw errors for HTTP status codes like 404.&lt;/p&gt;

&lt;p&gt;We shall see later in this guide how to handle 404 errors manually using the &lt;code&gt;reponse.ok&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling HTTP Requests
&lt;/h2&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%2Fv0pp2dvataywxvts56or.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%2Fv0pp2dvataywxvts56or.png" alt="Handling HTTP Requests" width="800" height="436"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When making a GET request using &lt;code&gt;fetch(url)&lt;/code&gt;, your code returns a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;Promise&lt;/a&gt; that resolves into a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Response" rel="noopener noreferrer"&gt;Response&lt;/a&gt; object.&lt;/p&gt;

&lt;p&gt;Let’s take a look at a simple GET Request.&lt;/p&gt;

&lt;h3&gt;
  
  
  GET Request
&lt;/h3&gt;

&lt;p&gt;To illustrate a GET request, we will use a fun example of a free API resource that generates random sentences to make you sound &lt;a href="https://techy-api.vercel.app/" rel="noopener noreferrer"&gt;tech-savvy&lt;/a&gt;. You can generate as many random messages as you want with the API.&lt;/p&gt;

&lt;p&gt;You start by adding the API endpoint as an argument to &lt;code&gt;fetch()&lt;/code&gt; and use &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; promises to define what happens to the response body.&lt;/p&gt;

&lt;p&gt;Before parsing data into JSON, you should first check if the response was successful using &lt;code&gt;response.ok&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once successful, the code proceeds on to parse the response body into JSON and log the data to the console. The &lt;code&gt;.catch()&lt;/code&gt; block is there to handle any network errors or invalid responses.&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://techy-api.vercel.app/api/json&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="nf"&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;// Check if response is successful&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;ok&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="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Network error! Status: &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="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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="nx"&gt;response&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;// parse the response body into JSON&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="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;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// log data to the console&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;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&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="c1"&gt;// handle errors when request fails&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F55vkl9tq11ni4cqgodeh.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%2F55vkl9tq11ni4cqgodeh.png" alt=" " width="800" height="80"&gt;&lt;/a&gt;&lt;br&gt;
The result is a random message as shown above.&lt;/p&gt;
&lt;h3&gt;
  
  
  POST Request
&lt;/h3&gt;

&lt;p&gt;To make a POST, PUT, or DELETE request, you have to provide an options object that specifies the method, headers, and body as needed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Query Parameters
&lt;/h2&gt;

&lt;p&gt;When working with APIs, adding parameters helps you filter or modify the data you receive. Now let’s see how we can manipulate query parameters for API endpoints.&lt;/p&gt;

&lt;p&gt;We will use the &lt;a href="https://fakerapi.it/" rel="noopener noreferrer"&gt;Faker API&lt;/a&gt; to generate random addresses for any country of our choice. Take a look at the code below:&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="c1"&gt;// Initializing the API endpoint&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;apiUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://fakerapi.it/api/v2/addresses?_quantity=1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Initializing a query parameter&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryParam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;_country_code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en_CA&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;// Converting query parameter to string&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryStr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queryParam&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// API endpoint + query parameter&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addressUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;apiUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;queryStr&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addressUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;ok&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="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Network error! Status: &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="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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="nx"&gt;response&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="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;address&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;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result looks like this:&lt;/p&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%2Furs9aw4mgbudtzlnsn6v.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%2Furs9aw4mgbudtzlnsn6v.png" alt=" " width="800" height="313"&gt;&lt;/a&gt;&lt;br&gt;
The example above shows a dummy address generated from the Faker API filtered for the Canada region.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using async/await with the Fetch API
&lt;/h2&gt;

&lt;p&gt;Async/await lets you simplify asynchronous operations using promises. The async function ensures the execution thread is not blocked, while the await block pauses execution until a promise is returned.&lt;/p&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%2F85i8zuq6m9i1hl7v2sd1.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%2F85i8zuq6m9i1hl7v2sd1.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We will still use Faker API to demonstrate how you can add async/await when making network requests. In the code below, we will create an async function &lt;code&gt;fetchAddress&lt;/code&gt; to help us generate random addresses from an API.&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="c1"&gt;// Initializing the API endpoint&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;apiUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://fakerapi.it/api/v2/addresses?_quantity=1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Initializing a query parameter and convering it to string&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryParam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;_country_code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en_CA&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryStr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queryParam&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// API endpoint + query parameter&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addressUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;apiUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;queryStr&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchAddress&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addressUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Check if response is successful&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;ok&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="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Network error. Status: &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="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&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;addressData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&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="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;addressData&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;error&lt;/span&gt;&lt;span class="p"&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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;fetchAddress&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is a randomly generated address as shown below:&lt;/p&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%2Fgy331e2o48t7wkeflqxl.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%2Fgy331e2o48t7wkeflqxl.png" alt=" " width="800" height="439"&gt;&lt;/a&gt;&lt;br&gt;
Using &lt;code&gt;await fetch(addressUrl);&lt;/code&gt; removes the need to add multiple &lt;code&gt;.then()&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;Also, the &lt;code&gt;await response.json();&lt;/code&gt; pauses code execution until the response body is parsed to JSON.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error Handling
&lt;/h2&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%2F4quaayrrbd4340baucjt.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%2F4quaayrrbd4340baucjt.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;em&gt;(Source: &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Checking for errors when fetching data helps you identify potential issues that may make your app crash. The &lt;code&gt;try/catch&lt;/code&gt; block helps identify any errors when fetching requests and parsing the response. However, some HTTP error codes require you to log them manually.&lt;/p&gt;

&lt;p&gt;Here’s a recap of how we can catch errors in various sections of our code:&lt;/p&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%2Frl4zxsosftrrzz0gto8z.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%2Frl4zxsosftrrzz0gto8z.png" alt=" " width="800" height="383"&gt;&lt;/a&gt;&lt;br&gt;
So, how exactly does each code block help catch errors?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;if(!response.ok)&lt;/code&gt; code block checks for response status in the 200 to 299 range; otherwise, it logs an error.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;throw new Error();&lt;/code&gt; logs a custom message when the response fails.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;catch()&lt;/code&gt; block handles invalid responses and network issues.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;In this article, we have covered key concepts on using the Fetch API to make network requests. We have also seen how to use &lt;code&gt;async/await&lt;/code&gt; to make code more readable, and how to handle errors using &lt;code&gt;try/catch&lt;/code&gt; and &lt;code&gt;response.ok&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I hope this article has been of help to you.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Keep building! 🌟&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noopener noreferrer"&gt;Using the Fetch API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;Promise&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/fetch" rel="noopener noreferrer"&gt;Fetch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/javascript/how-to-use-the-javascript-fetch-api-to-get-data/" rel="noopener noreferrer"&gt;How To Use JavaScript Fetch API To Get Data?&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>api</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Setting Up Material for MkDocs in Linux</title>
      <dc:creator>Jan</dc:creator>
      <pubDate>Thu, 03 Jul 2025 09:00:08 +0000</pubDate>
      <link>https://dev.to/janetmutua/setting-up-material-for-mkdocs-in-linux-4fdg</link>
      <guid>https://dev.to/janetmutua/setting-up-material-for-mkdocs-in-linux-4fdg</guid>
      <description>&lt;p&gt;When crafting documentation using the &lt;strong&gt;Docs-as-code&lt;/strong&gt; approach, authors often use plain-text formats such as Markdown.&lt;/p&gt;

&lt;p&gt;One popular tool for rendering Markdown is MkDocs, a static site generator for project documentation. &lt;/p&gt;

&lt;p&gt;With MkDocs you can easily host your site on platforms like Netlify, GitHub Pages, GitLab Pages, just to mention but a few.&lt;/p&gt;

&lt;p&gt;In this article, we will focus on &lt;strong&gt;Material for MkDocs&lt;/strong&gt; a powerful documentation framework built on top of MkDocs.&lt;/p&gt;

&lt;p&gt;We will go through the setup process with installations done using &lt;code&gt;pip&lt;/code&gt;, the Python package manager and &lt;code&gt;Docker&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Before we get started here are some few things you will need:&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;You need to have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installed a recent version of Python&lt;/li&gt;
&lt;li&gt;Installed Python package manager, pip&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that if you are not familiar with Python, you can still install Material for MkDocs with Docker.&lt;/p&gt;

&lt;h1&gt;
  
  
  Project Setup
&lt;/h1&gt;

&lt;p&gt;We will begin our project setup using &lt;code&gt;pip&lt;/code&gt;. If you plan on using &lt;code&gt;Docker&lt;/code&gt; you can skip to the section below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation with Pip
&lt;/h2&gt;

&lt;p&gt;Material for MkDocs is published as a Python package. Therefore, you can install it with pip, ideally using a virtual environment.&lt;/p&gt;

&lt;p&gt;Let's begin by setting up a virtual environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Virtual Environment
&lt;/h3&gt;

&lt;p&gt;Initializing a virtual environment is important especially if you want to keep the dependencies of different projects separate.&lt;/p&gt;

&lt;p&gt;With a virtual environment, you can create an isolated Python interpreter for your project. This way, it's easy to avoid potential issues caused by updating libraries used by your system tools.&lt;/p&gt;

&lt;p&gt;Additionally, with a virtual environment, your teams can work in the same environment thus maintaining consistency across development and deployment. &lt;/p&gt;

&lt;p&gt;To create a new virtual environment, open your terminal and navigate to your project directory.&lt;/p&gt;

&lt;p&gt;Use the built in &lt;code&gt;venv&lt;/code&gt; module to set up a Python virtual environment called &lt;code&gt;venv&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To do so, run the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="n"&gt;venv&lt;/span&gt; &lt;span class="n"&gt;venv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, activate your virtual environment by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can install MkDocs material using &lt;code&gt;pip&lt;/code&gt; with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;mkdocs&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;material&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command lets you automatically install all dependencies including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MkDocs&lt;/li&gt;
&lt;li&gt;Markdown&lt;/li&gt;
&lt;li&gt;Pygments&lt;/li&gt;
&lt;li&gt;Python Markdown Extensions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation with Docker
&lt;/h2&gt;

&lt;p&gt;Opting for Docker for Material for MkDocs installation means that all dependencies come pre-installed.&lt;/p&gt;

&lt;p&gt;You get the following plugins bundled with the Docker image:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/byrnereese/mkdocs-minify-plugin" rel="noopener noreferrer"&gt;mkdocs-minify-plugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/datarobot/mkdocs-redirects" rel="noopener noreferrer"&gt;mkdocs-redirects&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use the &lt;a href="https://hub.docker.com/r/squidfunk/mkdocs-material/" rel="noopener noreferrer"&gt;Docker image&lt;/a&gt; to get started. Pull the image with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull squidfunk/mkdocs-material
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, note that the docker container is not suitable for deployment but for previewing purposes only.&lt;/p&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%2F6hz3pkc1qxcqwsn7oa01.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%2F6hz3pkc1qxcqwsn7oa01.png" alt=" " width="800" height="164"&gt;&lt;/a&gt;&lt;a href="https://squidfunk.github.io/mkdocs-material/getting-started/#with-pip-latest" rel="noopener noreferrer"&gt;(Source)&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting Up Your Site
&lt;/h1&gt;

&lt;p&gt;Now you can use the &lt;code&gt;mkdocs&lt;/code&gt; executable to bootstrap your project documentation. &lt;/p&gt;

&lt;p&gt;Proceed to open your project folder in VS Code. Before anything, make sure you have activated your virtual environment.&lt;/p&gt;

&lt;p&gt;Now open the terminal within VS Code and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdocs new &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are running MkDocs from within Docker, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PWD&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;:/docs squidfunk/mkdocs-material new &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will create a folder structure like the one illustrated below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
├─ docs/
│  └─ index.md
└─ mkdocs.yml

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

&lt;/div&gt;



&lt;p&gt;Now, to startup your new website run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdocs serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how your site should look like:&lt;/p&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%2Fvg3pw9qahou4mcl4rt4c.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%2Fvg3pw9qahou4mcl4rt4c.png" alt=" " width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Configuration
&lt;/h1&gt;

&lt;p&gt;Since the MkDocs site looks a little bland, the next step is to setup Material theme for an even better look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Material Theme
&lt;/h2&gt;

&lt;p&gt;In order to load material theme on your docs site, go to the &lt;code&gt;mkdocs.yml&lt;/code&gt; file and set the following configurations and save the changes.&lt;/p&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%2Fi76urqu4f64x1zedo8ox.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%2Fi76urqu4f64x1zedo8ox.png" alt=" " width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The result is a more cleaner and proffessional-looking static site.&lt;/p&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%2Fm00sriko8bud6nldospc.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%2Fm00sriko8bud6nldospc.png" alt=" " width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this article, we have covered the steps needed to setup an MkDocs site with the Material Design theme. Now you can create more seamless documentation for your commercial or open source projects.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Keep building! 🌟&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://squidfunk.github.io/mkdocs-material/setup/" rel="noopener noreferrer"&gt;Material for MkDocs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://hub.docker.com/r/squidfunk/mkdocs-material/" rel="noopener noreferrer"&gt;MkDocs-material&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>tutorial</category>
      <category>linux</category>
      <category>tooling</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Installing Android Studio On Ubuntu 22.04: Complete Guide</title>
      <dc:creator>Jan</dc:creator>
      <pubDate>Tue, 04 Apr 2023 13:08:42 +0000</pubDate>
      <link>https://dev.to/janetmutua/installing-android-studio-on-ubuntu-2204-complete-guide-1kh8</link>
      <guid>https://dev.to/janetmutua/installing-android-studio-on-ubuntu-2204-complete-guide-1kh8</guid>
      <description>&lt;p&gt;&lt;em&gt;Are you new to Android Development?&lt;/em&gt; And do you want to learn how to setup your &lt;strong&gt;Integrated Development Environment (IDE)&lt;/strong&gt; for building your projects? Then you are in the right place!&lt;/p&gt;

&lt;p&gt;Android Studio is the &lt;strong&gt;official IDE&lt;/strong&gt; for developing Android apps. It comes with powerful features that help you build your applications faster and easier.&lt;/p&gt;

&lt;p&gt;For Linux users, this guide will take you through the nitty gritty of getting your IDE setup. &lt;strong&gt;Let's get started!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  System Requirements
&lt;/h2&gt;

&lt;p&gt;Since we are setting up on Linux, here are the system requirements as listed on the &lt;a href="https://developer.android.com/studio#downloads" rel="noopener noreferrer"&gt;Official download page&lt;/a&gt; for Android Studio:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;x86_64 CPU architecture; 2nd generation Intel Core or newer, or AMD processor with support for AMD Virtualization (AMD-V) and SSSE3.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any 64-bit Linux distribution that supports Gnome, KDE, or Unity DE; GNU C Library (glibc) 2.31 or later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A minimum 8 GB of available disk space for your IDE, Android SDK and the Android Emulator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;8 GB RAM or more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;1280 x 800 minimum screen resolution.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your computer meets these requirements then let's get started with the installations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1:Manually Installing Android Studio (From the Official &amp;amp; PPA Repositories)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installing From the Official Repository
&lt;/h3&gt;

&lt;p&gt;You can install Android Studio from the official repository. To begin, open up your terminal and then update and upgrade your APT repository by running the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt update
$ sudo apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then install OpenJDK, a free and open-source implementation of the Java platform, Standard Edition (Java SE). To do so run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install openjdk-18-jdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can proceed to install your IDE by downloading a zip file of the latest version of Android studio on your machine. &lt;/p&gt;

&lt;p&gt;At the time of writing this article, the latest version of Android Studio is the Electric Eel version. Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ wget https://dl.google.com/dl/android/studio/ide-zips/2022.1.1.21/android-studio-2022.1.1.21-linux.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or you can check for the version you want from the &lt;a href="https://developer.android.com/studio/archive" rel="noopener noreferrer"&gt;Android Studio Download archive&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After successful download, you need to unpack the downloaded zip file with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tar -zxvf android-studio-2022.1.1.21-linux.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then move the android-studio folder to &lt;code&gt;/opt/&lt;/code&gt; using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo mv android-studio /opt/
$ sudo ln -sf /opt/android-studio/bin/studio.sh /bin/android-studio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have run these commands, you will write a snippet of code to allow for the Android Studio application to be available on the application menu shortcut on Ubuntu.&lt;/p&gt;

&lt;p&gt;Using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo nano /usr/share/applications/android-studio.desktop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following code snippet and save:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;Desktop Entry]
&lt;span class="nv"&gt;Version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1.0
&lt;span class="nv"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Application
&lt;span class="nv"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Android Studio
&lt;span class="nv"&gt;Comment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Android Studio
&lt;span class="nv"&gt;Exec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bash &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s2"&gt;"/opt/android-studio/bin/studio.sh"&lt;/span&gt; %f
&lt;span class="nv"&gt;Icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/android-studio/bin/studio.png
&lt;span class="nv"&gt;Categories&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Development&lt;span class="p"&gt;;&lt;/span&gt;IDE&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;Terminal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false
&lt;/span&gt;&lt;span class="nv"&gt;StartupNotify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="nv"&gt;StartupWMClass&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;jetbrains-android-studio
Name[en_GB]&lt;span class="o"&gt;=&lt;/span&gt;android-studio.desktop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From there you can open and run your android studio from the activities or on the applications menu.&lt;/p&gt;

&lt;h3&gt;
  
  
  Uninstalling Android Studio - Official Repository
&lt;/h3&gt;

&lt;p&gt;If you installed Android Studio from the Official repository, run the following commands to uninstall the IDE:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo rm /usr/share/applications/android-studio.desktop
$ sudo rm -r /usr/bin/android-studio
$ sudo rm -rf /opt/android-studio
$ rm -rf ~/android-studio-2022.1.1.21-linux.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will completely uninstall all the packages that were installed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Android Studio From the PPA Repository
&lt;/h3&gt;

&lt;p&gt;You can also get your IDE from the PPA repository - an Ubuntu based software repository. To begin install OpenJDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install openjdk-18-jdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check to see the java version installed above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ java -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then import PPA and update your APT repository using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo add-apt-repository ppa:maarten-fonville/android-studio
$ sudo apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once complete, you can install Android Studio through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install android-studio -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Uninstalling Android studio - PPA repository
&lt;/h3&gt;

&lt;p&gt;If you need to remove Android Studio from your machine, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt autoremove android-studio --purge -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then remove the imported PPA using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo add-apt-repository --remove ppa:maarten-fonville/android-studio -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, Android Studio and all the installed packages will have been removed completely&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 2: Installing Android Studio Using Snap
&lt;/h2&gt;

&lt;p&gt;Another way you can use to install Android Studio is by using Snap - a package management system by Canonical. To do so, first run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install snapd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then install OpenJDK and Android Studio using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install openjdk-18-jdk
$ sudo snap install android-studio --classic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, proceed to launch Android Studio by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ android-studio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Uninstalling Android Studio - Snap
&lt;/h3&gt;

&lt;p&gt;Removing Android Studio installed using snap is quite easy. You simply need to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo snap remove android-studio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Method 3: Installing Android Studio Using JetBrains Toolbox
&lt;/h2&gt;

&lt;p&gt;The third method you can use to install Android Studio is by using the Toolbox app which gives you access to developer products made by Jetbrains.&lt;/p&gt;

&lt;p&gt;If you don't know how to install Toolbox, &lt;a href="https://dev.to/janetmutua/installing-jetbrains-toolbox-on-ubuntu-527f"&gt;here is a guide on how to&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you have Toolbox on your machine, click to open it, then select Android Studio and click install. You will get the latest version of the IDE installed in your machine.&lt;/p&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%2F6zflxn5auzi543nkig2k.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%2F6zflxn5auzi543nkig2k.png" alt="Download Android Studio" width="438" height="613"&gt;&lt;/a&gt;&lt;br&gt;
If you prefer to install a specific version of Android Studio, you can check the available versions and install the one you prefer.&lt;/p&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%2Fqlfah81niuezltragvli.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%2Fqlfah81niuezltragvli.png" alt="Android Studio Versions" width="436" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Uninstalling Android Studio - Jetbrains Toolbox
&lt;/h2&gt;

&lt;p&gt;To remove Android Studio just open the Toolbox App and click the menu button adjacent to Android Studio option to see an uninstall option. &lt;/p&gt;

&lt;p&gt;This will remove Android Studio and all the packages that were installed with it.&lt;/p&gt;

&lt;p&gt;With that, you can select whichever method suits you and get your IDE setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus Tip: Using Wakatime For Your Coding Productivity!
&lt;/h2&gt;

&lt;p&gt;Enhancing your productivity while coding means that you can get more done and build better software. One such plugin that can increase your productivity is &lt;em&gt;Wakatime&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Wakatime&lt;/em&gt; is used for time tracking meaning you can manage and analyze how much time you spend coding daily. In the spirit of building in public, &lt;em&gt;Wakatime&lt;/em&gt; can help you share your metrics on Twitter or LinkedIn. &lt;/p&gt;

&lt;p&gt;What's more, you can include your programming metrics on your Markdown file on Github. Once you have installed Android Studio, head over to &lt;code&gt;Settings/plugins&lt;/code&gt; and search for &lt;em&gt;Wakatime&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Install it and &lt;em&gt;restart&lt;/em&gt; your IDE, then go ahead and change the world one minute at a time!&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/studio/archive" rel="noopener noreferrer"&gt;Android Studio download archives&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.android.com/studio#downloads" rel="noopener noreferrer"&gt;Latest version of Android Studio&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.ubuntu-server.com/ubuntu/how-to-install-android-studio-on-ubuntu-22-04/" rel="noopener noreferrer"&gt;Ubuntu-Server.com&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In this guide we have covered three ways of installing the Android Studio IDE. Properly setting up your IDE allows you to develop your applications smoothly with no bumps. I hope this article has been of help to you.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Keep building! 🌟&lt;/p&gt;

</description>
      <category>android</category>
      <category>jetbrains</category>
      <category>ubuntu</category>
      <category>installations</category>
    </item>
    <item>
      <title>Installing JetBrains ToolBox on Ubuntu</title>
      <dc:creator>Jan</dc:creator>
      <pubDate>Tue, 21 Mar 2023 13:46:23 +0000</pubDate>
      <link>https://dev.to/janetmutua/installing-jetbrains-toolbox-on-ubuntu-527f</link>
      <guid>https://dev.to/janetmutua/installing-jetbrains-toolbox-on-ubuntu-527f</guid>
      <description>&lt;p&gt;If you need an easier way to install JetBrains products such as IntelliJ IDEA, Android Studio, PyCharm, or PhpStorm, etc, you can do so using their Toolbox.&lt;/p&gt;

&lt;p&gt;JetBrains developed their own tool called the JetBrains Toolbox to assist developers in installing and updating any of their products. The Toolbox is free to use and comes with the option of managing your licenses.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will focus on the installation process of Toolbox, how to install applications, how to configure it, and how to uninstall it from your machine. Let's get to it!&lt;/p&gt;

&lt;h1&gt;
  
  
  System requirements
&lt;/h1&gt;

&lt;p&gt;Before you install JetBrains Toolbox on your machine, here are the system requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Linux : 64-bit x86, glibc (Ubuntu 18.04 or newer). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You also require the following packages to start the JetBrains Toolbox: &lt;code&gt;libfuse2 libxi6 libxrender1 libxtst6 mesa-utils libfontconfig libgtk-3-bin&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: JetBrains Toolbox is packed in AppImage and requires FUSE to run.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Installing Jetbrains Toolbox
&lt;/h1&gt;

&lt;p&gt;To begin installing Toolbox, go ahead and visit the &lt;a href="https://www.jetbrains.com/toolbox-app/" rel="noopener noreferrer"&gt;official site&lt;/a&gt; and download the archived installer. &lt;/p&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%2Fukwwa9xk2thnaebm384d.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%2Fukwwa9xk2thnaebm384d.png" alt="Download the Installer" width="800" height="551"&gt;&lt;/a&gt;&lt;br&gt;
You can also opt to use the terminal to retrive the installer, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ wget -c https://download.jetbrains.com/toolbox/jetbrains-toolbox-1.27.3.14493.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then proceed to extract the toolbox installer using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo tar -xzf jetbrains-toolbox-1.27.3.14493.tar.gz -C /opt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once complete, you can go ahead and open Jetbrains Toolbox to start installing the applications you want.&lt;/p&gt;

&lt;p&gt;On the terminal, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ /opt/jetbrains-toolbox-1.27.3.14493/jetbrains-toolbox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In some instances, you might get a failure message about a missing FUSE2. If this happens, proceed to manually install it using the:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get install -y libfuse2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successful installation, the next step is configuring your Toolbox and installing applications.&lt;/p&gt;

&lt;h1&gt;
  
  
  Configuring JetBrains Toolbox and Installing Applications
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Configurations
&lt;/h3&gt;

&lt;p&gt;The Toolbox comes with several settings options for its users. Select the &lt;code&gt;settings&lt;/code&gt; option and your screen should look like this:&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%2Ftxp39na44wqhnybuci3r.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%2Ftxp39na44wqhnybuci3r.png" alt="Settings menu" width="441" height="615"&gt;&lt;/a&gt;&lt;br&gt;
ToolBox lets you login to your JetBrains account and manage your licences. &lt;/p&gt;

&lt;p&gt;You can also disable the option to launch on system startup. To do so, click the settings option as shown above or press &lt;code&gt;Ctrl + Comma&lt;/code&gt;. On the settings menu, uncheck the "Launch Toolbox App at system startup."&lt;/p&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%2Fy5wz846fsx7xt12dm616.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%2Fy5wz846fsx7xt12dm616.png" alt="Launch Toolbox" width="440" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, you can toggle your theme settings by selecting between Light, System and Dark themes.&lt;/p&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%2Fomrr2ov626zyd64i517q.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%2Fomrr2ov626zyd64i517q.png" alt="Light and Dark Theme" width="440" height="610"&gt;&lt;/a&gt;&lt;br&gt;
If you want to change the installation path for any applications installed using Toolbox, select the dropdown &lt;code&gt;Tools&lt;/code&gt; then edit the "Tools install location" option to your desired path.&lt;/p&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%2Fe0hfo54mvxxk5vlo1jal.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%2Fe0hfo54mvxxk5vlo1jal.png" alt="Tools install location" width="429" height="608"&gt;&lt;/a&gt;&lt;br&gt;
In addition, Toolbox lets you save on disk space. To enable this option, still under the &lt;code&gt;Tools&lt;/code&gt; dropdown, turn off "Keep previous versions of tools to enable instant rollback."&lt;/p&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%2Fr45wfca95nsyup7lutqs.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%2Fr45wfca95nsyup7lutqs.png" alt="Previous vesions" width="433" height="612"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing Applications
&lt;/h3&gt;

&lt;p&gt;You can install different applications/Integrated Development Environments(IDEs) from the Jetbrains Toolbox. &lt;/p&gt;

&lt;p&gt;All you have to do is go to the &lt;code&gt;tools&lt;/code&gt; menu option which is also the home page when you launch the toolbox. &lt;/p&gt;

&lt;p&gt;Scroll down to discover any IDEs that may be of use to you then click Install. &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%2Fvne38j8a7wpwd6ahfcps.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%2Fvne38j8a7wpwd6ahfcps.png" alt="Installing apps" width="438" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also uninstall or revert to different versions of an application, as shown in the menu options below.&lt;/p&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%2F9rfu083puutefqfgq5hm.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%2F9rfu083puutefqfgq5hm.png" alt="App Options Menu" width="436" height="614"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  How to Uninstall Jetbrains Toolbox
&lt;/h1&gt;

&lt;p&gt;Suppose you want to remove Toolbox from your machine. First, you need to uninstall all applications installed in Toolbox App. &lt;/p&gt;

&lt;p&gt;Once done, uncheck 'Run at login' in Toolbox App settings or do so using the terminal using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ~/.config/autostart/jetbrains-toolbox.desktop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, exit the Toolbox App, and on your terminal, run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rm -rf ~/.local/share/JetBrains/Toolbox
$ rm -rf ~/.local/share/applications/jetbrains-toolbox.desktop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is it; you will have successfully uninstalled toolbox!&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://toolbox-support.jetbrains.com/hc/en-us/sections/115000264010-FAQ" rel="noopener noreferrer"&gt;Toolbox App Support&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In this article you have learnt how to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the Jetbrains Toolbox App,&lt;/li&gt;
&lt;li&gt;Configure the Toolbox app to your preferences,&lt;/li&gt;
&lt;li&gt;Install Jetbrains Applications using the Toolbox,&lt;/li&gt;
&lt;li&gt;And uninstalling Toolbox.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can use this app to get access to latest versions of Jetbrains products including Android Studio, IntelliJ IDEA, Pycharm and many more.&lt;/p&gt;

&lt;p&gt;With Toolbox App, you can easily revert or upgrade to different versions at the click of a button, hence you can focus on building in an updated IDE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for reading. Keep building!&lt;/strong&gt; 🌟   &lt;/p&gt;

</description>
      <category>jetbrains</category>
      <category>toolbox</category>
      <category>intellijidea</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Setting up a Django Project On Ubuntu 22.04 - Beginners Guide</title>
      <dc:creator>Jan</dc:creator>
      <pubDate>Mon, 06 Mar 2023 15:47:06 +0000</pubDate>
      <link>https://dev.to/janetmutua/setting-up-a-django-project-on-ubuntu-beginners-guide-5ep2</link>
      <guid>https://dev.to/janetmutua/setting-up-a-django-project-on-ubuntu-beginners-guide-5ep2</guid>
      <description>&lt;p&gt;Django is a python-based web framework that follows the &lt;strong&gt;model-template-views (MTV) architectural pattern&lt;/strong&gt;. It comes with ready-made components to use, and you can build versatile and scalable web applications with it. &lt;/p&gt;

&lt;p&gt;But how do you setup your Django project, and if you are using Ubuntu, what are the recommended installation packages needed?&lt;/p&gt;

&lt;p&gt;By the end of this guide you will learn how to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set up a virtual environment.&lt;/li&gt;
&lt;li&gt;Install Python and Django.&lt;/li&gt;
&lt;li&gt;Set up a Django project from scratch.&lt;/li&gt;
&lt;li&gt;Set up Django apps.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Before you begin setting up your new Django project, here are a few prerequisites that are needed. You should have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of how to use the terminal.&lt;/li&gt;
&lt;li&gt;Knowledge of how to install software packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With that said, here are the steps you need to follow to set up your Django project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 - Setting Up Your Environment
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installations
&lt;/h3&gt;

&lt;p&gt;There are several installations required for you to successfully start a Django project. They include: &lt;code&gt;Python&lt;/code&gt;, &lt;code&gt;Pip&lt;/code&gt; and &lt;code&gt;Virtualenv&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Below you will find guidelines on how to install each one of them.&lt;/p&gt;

&lt;h4&gt;
  
  
  Python
&lt;/h4&gt;

&lt;p&gt;Since Django is a python-based web framework, the first thing you need to do is check if Python is installed on your machine.&lt;/p&gt;

&lt;p&gt;Open up the terminal and ensure that you are the root user. &lt;/p&gt;

&lt;p&gt;If you have previously installed python on your machine, type the following command to check the version available.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Otherwise, you can begin by installing the latest version of python. Start by updating and upgrading your APT repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get update
$ sudo apt-get -y upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once complete, install the latest version of python:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Check to see the version of python your machine is currently running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Pip
&lt;/h4&gt;

&lt;p&gt;The next step is to set up pip, a Python-based package manager. To get the latest version of pip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get install -y python3 pip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the version of Pip installed using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip3 -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have Python and Pip, you can now install your virtual environment and setup your Django project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Virtual environment
&lt;/h4&gt;

&lt;p&gt;A virtual environment is a Python tool for managing dependencies and isolating projects.&lt;/p&gt;

&lt;p&gt;It enables local installation of Python site packages (third-party libraries) for a specific project as opposed to global installation.&lt;/p&gt;

&lt;p&gt;To set up a virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip3 install virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successful installation, you can check the version using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ virtualenv --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Preparing Your Environment
&lt;/h3&gt;

&lt;p&gt;To begin preparing your environment for your Django project, navigate to a folder that holds any/all of your projects. &lt;/p&gt;

&lt;p&gt;For the sake of this tutorial, our &lt;code&gt;projects&lt;/code&gt; folder is found on the desktop.&lt;/p&gt;

&lt;p&gt;Change the directory to the project folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~$ cd Desktop/projects
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a new folder for your Django project and navigate into it. You will name your Django project folder however you please. Here we will use &lt;code&gt;blogSite/&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/Desktop/projects$ mkdir blogSite
~/Desktop/projects$ cd blogSite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, set up a new virtual environment. You can call your virtual environment &lt;code&gt;env&lt;/code&gt;. To set up a virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ virtualenv env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then activate the virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ source env/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see the &lt;code&gt;(env)&lt;/code&gt; prefixed on the path to your current directory. If you wish to deactivate the virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ deactivate env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To know that the deactivation has worked, you will no longer see the &lt;code&gt;(env)&lt;/code&gt; prefix on your path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Installing Django and Dependency Pinning
&lt;/h2&gt;

&lt;p&gt;Next,you will proceed to install Django and setup your project. &lt;/p&gt;

&lt;p&gt;Django is a &lt;strong&gt;high-level Python web framework&lt;/strong&gt; that promotes rapid development and pragmatic design. &lt;/p&gt;

&lt;p&gt;Django comes with ready-made components to use, allowing you to focus on the development of your web applications rather than the underlying infrastructure.&lt;/p&gt;

&lt;p&gt;To install Django:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ python3 -m pip install django
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see this after successful installation.&lt;/p&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%2Ffkud55sybznyujx7dn8v.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%2Ffkud55sybznyujx7dn8v.png" alt="Successful-Installation" width="742" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, pin your dependencies to a &lt;code&gt;requirements.txt&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;This allows you and other developers to replicate the exact conditions of your project build. &lt;/p&gt;

&lt;p&gt;Type the following command on your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ python3 -m pip freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your directory should now be looking like this:&lt;/p&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%2Fbjksdo3bwwao74hdy03f.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%2Fbjksdo3bwwao74hdy03f.png" alt="Your-blogSite-directory-view" width="309" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: To install a specific version of Django add the version number to the installation command:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ python3 -m pip install django==4.1.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, if you want to install dependencies from a pre-existing project use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ python3 -m pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3 - Project Setup
&lt;/h2&gt;

&lt;p&gt;A Django project is a &lt;strong&gt;high-level unit of organization&lt;/strong&gt; for a collection of configuration apps for your website. Your Django project can have multiple apps.&lt;/p&gt;

&lt;p&gt;In this section, you will make a skeleton Django website. As mentioned above, Django already comes with ready-made components to use.&lt;/p&gt;

&lt;p&gt;To begin with, start a new project called &lt;code&gt;myBlog&lt;/code&gt;. This will create a &lt;code&gt;myBlog/&lt;/code&gt; folder on your current directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ django-admin startproject myBlog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then change your directory to the newly created project/folder by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ cd myBlog/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: Do not name your projects after built-in Django/Python components such as &lt;code&gt;Django&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;startproject&lt;/code&gt; command created:&lt;/p&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%2Fzx579ud5vhre0xibnyrv.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%2Fzx579ud5vhre0xibnyrv.png" alt="Project-directory-breakdown" width="610" height="336"&gt;&lt;/a&gt;&lt;br&gt;
Here is a run down of the files and folders in the &lt;code&gt;myBlog/&lt;/code&gt; directory/folder.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;myBlog/&lt;/code&gt; - acts as the container for your projects and can be renamed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;manage.py&lt;/code&gt; - it is a command line utility that lets you interact with Django. With &lt;code&gt;manage.py&lt;/code&gt; you can create apps, work with databases and start the development server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;myBlog/&lt;/code&gt; - this is the actual python package for your project. You will use the package name &lt;code&gt;myBlog&lt;/code&gt; for importing anything you need in your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;__init.py__&lt;/code&gt; - it is an empty file that tells Python that this directory should be considered a Python package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;settings.py&lt;/code&gt; - this file contains details on database configuration, location of your project's static files and it is where you register any applications (&lt;code&gt;apps&lt;/code&gt;) made.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;urls.py&lt;/code&gt; - this file acts as a Table of Contents for your project. You can make URL declarations and define the site's URL-to-view mappings on this file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;asgi.py&lt;/code&gt; - acts as an entry point for ASGI-compatible web servers to serve your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;wsgi.py&lt;/code&gt; - acts as an entry point for WSGI-compatible web servers to serve your project.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Step 4 - Powering Up the Development Server
&lt;/h2&gt;

&lt;p&gt;Next, you need to learn how to power up the development server for your new &lt;code&gt;myBlog&lt;/code&gt; project/site.&lt;/p&gt;

&lt;p&gt;To power up your new Django project development server, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ python3 manage.py runserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your project is running successfully you will see:&lt;/p&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%2Fnchay270yzwb93t2sl6w.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%2Fnchay270yzwb93t2sl6w.png" alt="Powering-the-server" width="800" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will also see a warning indicating that there are unapplied migrations.&lt;/p&gt;

&lt;p&gt;Ignore the unapplied migrations warning and proceed to open the development server on the port &lt;code&gt;http://127.0.0.1:8000/&lt;/code&gt;.&lt;/p&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%2Fea6h6e89ni8gjotxknkr.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%2Fea6h6e89ni8gjotxknkr.png" alt="development-server" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To exit the development server on your terminal use &lt;code&gt;Ctrl + C&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 - Creating Your First App
&lt;/h2&gt;

&lt;p&gt;Now that you have already set up your environment and created your Django project, you can proceed to set up your first app. &lt;/p&gt;

&lt;p&gt;A Django app is the &lt;strong&gt;low-level unit&lt;/strong&gt; of your web application. You can create your app anywhere on the Python path. &lt;/p&gt;

&lt;p&gt;However, the best practice is to have all the apps of your project in the same directory as &lt;code&gt;manage.py&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This means that your app will be imported as its own top-level module rather than a submodule of your project.&lt;/p&gt;

&lt;p&gt;Therefore, ensure you are in the same directory as &lt;code&gt;manage.py&lt;/code&gt; then type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env)$ python3 manage.py startapp newsPage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a &lt;code&gt;newsPage/&lt;/code&gt; directory with the following structure:&lt;/p&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%2Fefuxj1yys50eunforsq2.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%2Fefuxj1yys50eunforsq2.png" alt="Django-app-directory-breakdown" width="560" height="312"&gt;&lt;/a&gt;&lt;br&gt;
Django auto-generates the basic directory structure of the &lt;code&gt;newsPage&lt;/code&gt; app.&lt;/p&gt;

&lt;p&gt;Most of these files and folders are named after their intended purpose.&lt;/p&gt;

&lt;p&gt;Let us take a look at what each of these files are meant for.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;newsPage/&lt;/code&gt; - actual app folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;__init__.py&lt;/code&gt; - this file allows Django to use code from different apps to compose the overall functionality of your web application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;admin.py&lt;/code&gt;- this file is where you will do the admin site configuration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;apps.py&lt;/code&gt;- file meant for application registration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;migrations/&lt;/code&gt;- folder that stores migrations files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;migrations/__init__.py&lt;/code&gt; - is a migration file that allows you to update your database automatically as you change your models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;- file where all you will design all your models. This file contains code that allows Django to communicate with your web application's database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;views.py&lt;/code&gt;- this is the file that houses most of the web app's code logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With this, you have already built a skeleton web application with Django, the next step is to build your site's views, models and migrate your databases. For more guidance on creating views, models, and URL interlinking, read more from the &lt;a href="https://docs.djangoproject.com/en/4.1/intro/tutorial01/" rel="noopener noreferrer"&gt;Official Documentation.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/4.1/intro/tutorial01/" rel="noopener noreferrer"&gt;Django official Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/development_environment" rel="noopener noreferrer"&gt;MDN Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://realpython.com/django-setup/#prepare-your-environment" rel="noopener noreferrer"&gt;Real Python&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In this article, you have learned:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How to prepare your environment and perform the necessary installations&lt;/li&gt;
&lt;li&gt;How to set up a Django project from scratch&lt;/li&gt;
&lt;li&gt;How to power your development server&lt;/li&gt;
&lt;li&gt;And how to create your first Django app.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We have covered all the steps necessary to get a Django web app up and running. You can go ahead and find and project idea you like and implement it. Django is a powerful web framework for those who want to build fast. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for reading. Keep building!&lt;/strong&gt; 🌟&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>ubuntu</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
