<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Abhishek Kumar</title>
    <description>The latest articles on Forem by Abhishek Kumar (@abhishek_writes).</description>
    <link>https://forem.com/abhishek_writes</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%2F974643%2F1ccfb149-8569-43d6-bd44-8a468cb74af8.jpeg</url>
      <title>Forem: Abhishek Kumar</title>
      <link>https://forem.com/abhishek_writes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abhishek_writes"/>
    <language>en</language>
    <item>
      <title>Understanding defer in Go: Best Practices, and Why It Matters</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Wed, 10 Sep 2025 17:54:38 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/understanding-defer-in-go-best-practices-common-pitfalls-and-why-it-matters-c2e</link>
      <guid>https://forem.com/abhishek_writes/understanding-defer-in-go-best-practices-common-pitfalls-and-why-it-matters-c2e</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Go's &lt;code&gt;defer&lt;/code&gt; Statement: A Complete Guide
&lt;/h2&gt;

&lt;p&gt;Have you ever written a Go code? Of course you have - that's why this post is recommended to you! And if your answer is yes, then you might have come across the keyword &lt;code&gt;defer&lt;/code&gt;. So let's understand this in detail so that we can write better Go code (after all, as gophers our aim is to write code that works and not fall for anything like other language folks do, haha just kidding).&lt;/p&gt;




&lt;h2&gt;
  
  
  But What is &lt;code&gt;defer&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;So if you look for the official definition it goes like: "&lt;code&gt;defer&lt;/code&gt; schedules a function call to run &lt;strong&gt;right after the surrounding function returns&lt;/strong&gt;". Ok but what does this actually mean? In simple terms, this means that any function call preceded by &lt;code&gt;defer&lt;/code&gt; is added to a stack of deferred calls and will be executed just before the parent function (where the defer is declared) exits.&lt;/p&gt;

&lt;p&gt;The deferred calls are executed in Last-In, First-Out (LIFO) order.&lt;/p&gt;

&lt;h2&gt;
  
  
  So How Does &lt;code&gt;defer&lt;/code&gt; Work?
&lt;/h2&gt;

&lt;p&gt;Let's take a code example which will help us understand this better and clear up what is the LIFO execution that we talked about earlier. So below is a simple Go code with some addition and some print statements. I think this is a pretty simple yet effective example to understand defer without buzzwords.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;54&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;34&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Prints the sum immediately&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"from defer: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello world from defer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, World!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any guesses what will be the output? Let's look at the output first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;88
Hello, World!
hello world from defer
from defer: 88
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why and How This Happens
&lt;/h2&gt;

&lt;p&gt;Let's analyze the execution flow of Go's &lt;code&gt;defer&lt;/code&gt; statement step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step-by-Step Execution
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Immediate Execution:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Computes &lt;code&gt;c = a + b&lt;/code&gt; → &lt;code&gt;88&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Prints: &lt;code&gt;88&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Deferring Function Calls:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"from defer: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello world from defer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Arguments are evaluated immediately:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;a + b&lt;/code&gt; → &lt;code&gt;88&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"hello world from defer"&lt;/code&gt; is ready&lt;/li&gt;
&lt;li&gt;Functions themselves are pushed onto a stack for later execution&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Regular Execution Continues:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Prints: &lt;code&gt;Hello, World!&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Deferred Functions Execute in Reverse (LIFO):
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;First&lt;/strong&gt;, prints the last deferred call:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   hello world from defer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Then&lt;/strong&gt;, prints the first deferred call:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   from defer: 88
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complete Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;88
Hello, World!
hello world from defer
from defer: 88
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Arguments to deferred functions are evaluated when &lt;code&gt;defer&lt;/code&gt; is encountered&lt;/li&gt;
&lt;li&gt;Deferred functions execute in Last-In-First-Out (LIFO) order
&lt;/li&gt;
&lt;li&gt;Deferred functions run just before the surrounding function returns&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More Common Use Cases: File Handling
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"example.txt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error opening file:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Ensure the file gets closed when the function exits&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"File opened successfully."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Here, &lt;code&gt;file.Close()&lt;/code&gt; is guaranteed to run at the end of &lt;code&gt;main()&lt;/code&gt;, even if the function returns early due to an error. This helps a lot in resource cleanup and making sure the file is closed after usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ok, So We've Understood defer, Now Let's Do Something Fun
&lt;/h2&gt;

&lt;p&gt;One interesting trick with &lt;code&gt;defer&lt;/code&gt; is reversing a string without using loops or extra arrays. Since deferred functions execute in Last-In, First-Out (LIFO) order, we can take advantage of this to print characters in reverse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"golang"&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Reversed word: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// capture the character immediately&lt;/span&gt;
        &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%c"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Each iteration of the loop defers printing a character&lt;/li&gt;
&lt;li&gt;Deferred calls are stacked, so they execute in reverse order when &lt;code&gt;main()&lt;/code&gt; ends&lt;/li&gt;
&lt;li&gt;The result is the string printed backwards:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reversed word: gnalog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;I hope this post has helped you understand &lt;code&gt;defer&lt;/code&gt; in an easy and fun way!&lt;/p&gt;

&lt;p&gt;Happy coding in Go! 🐹&lt;/p&gt;

</description>
      <category>go</category>
      <category>backend</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Create a Simple Live Server Extension Using Golang</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Thu, 26 Sep 2024 04:27:46 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/how-to-create-a-simple-live-server-extension-using-golang-2k0e</link>
      <guid>https://forem.com/abhishek_writes/how-to-create-a-simple-live-server-extension-using-golang-2k0e</guid>
      <description>&lt;p&gt;If you are a web developer and haven't used the Live Server extension in VSCode, are you even a developer? Just kidding. But have you thought about how that works under the hood? In today’s blog, let’s try to understand how that works with a hands-on implementation using Golang. Why Golang? Well, I am exploring Golang these days, and what’s better to learn than building a project? So enough context (not the one in golang ) let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  How live server works ?
&lt;/h2&gt;

&lt;p&gt;So the live server automatically reloads the browser whenever it detects any modification in html,css or js files. It began by serving these static files through a HTTP server. Under the hood it employs a file watcher like &lt;a href="https://github.com/fsnotify/fsnotify" rel="noopener noreferrer"&gt;fsnotify&lt;/a&gt;( we are going to use this for our project) , &lt;a href="https://github.com/emcrisostomo/fswatch" rel="noopener noreferrer"&gt;fswatch&lt;/a&gt; (in UNIX-based file system) or &lt;a href="https://www.npmjs.com/package/chokidar" rel="noopener noreferrer"&gt;Chokidar&lt;/a&gt;(for Nodejs) to continuously monitor the project’s directory for file changes (basically when you save any file with extensions .html,.css,.js ) .&lt;/p&gt;

&lt;p&gt;At the core it Uses a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API" rel="noopener noreferrer"&gt;WebSocket&lt;/a&gt; connection between the your (node js) server and the browser. When the server detects a file changes it sends a reload notification through WebSocket to the browser. The browser , in turn, reloads the page to reflect the new changes being made. Additionally it uses CSS injection(updating only styles without a full reload) ,HMR(hot module replacement) for javascript module. This ensures the developer get’s a real time feedback without the need of manually reloading the browser after each change in code .&lt;/p&gt;

&lt;h2&gt;
  
  
  Project overview
&lt;/h2&gt;

&lt;p&gt;So with this project, my idea was the same. My goal was to watch for file changes (like HTML, CSS, and JavaScript) and trigger a browser reload whenever any modifications were detected. For this, I used Go's built-in HTTP server and the &lt;code&gt;fsnotify&lt;/code&gt; package, which efficiently monitors file system events.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Serving Static Files
&lt;/h2&gt;

&lt;p&gt;The first step was to set up a simple HTTP server in Go that serves static files from a directory. The static files, such as HTML, CSS, and JavaScript, would be loaded from the &lt;code&gt;./static&lt;/code&gt; folder. This is handled using the &lt;code&gt;http.FileServer&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"./static"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Reload Endpoint
&lt;/h2&gt;

&lt;p&gt;Next, I needed an endpoint that would notify the client to reload when a file change was detected. The &lt;code&gt;/reload&lt;/code&gt; route acts as a trigger, sending a "reload" message to the browser when the server detects a modification:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/reload"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&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;lt;-&lt;/span&gt;&lt;span class="n"&gt;reloadChan&lt;/span&gt;
    &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"reload"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This route listens for events on a channel, which will later be populated by file change notifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Watching File Changes
&lt;/h2&gt;

&lt;p&gt;I leveraged the &lt;code&gt;fsnotify&lt;/code&gt; package to track changes in specific file types (HTML, CSS, and JS). The watcher listens for any modifications and pushes a notification to the reload channel when it detects changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;scanFileChanges&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;watcher&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fsnotify&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewWatcher&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;watcher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;watcher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Events&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Op&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;fsnotify&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;fsnotify&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;isTrackedFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Modified File:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;reloadChan&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;watcher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errors&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Filtering Tracked Files
&lt;/h2&gt;

&lt;p&gt;Not every file change should trigger a reload, so I added a filter that only tracks specific file extensions: &lt;code&gt;.html&lt;/code&gt;, &lt;code&gt;.css&lt;/code&gt;, and &lt;code&gt;.js&lt;/code&gt;. This was done using the &lt;code&gt;filepath.Ext&lt;/code&gt; function to check file types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;isTrackedFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ToLower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Ext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;".html"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;".css"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;".js"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Running the Server
&lt;/h2&gt;

&lt;p&gt;Finally, I launched the HTTP server to listen on port 8000 and started the file watching process concurrently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Starting the server at: 8000"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListenAndServe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;":8000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;While this example focuses on reloading static files, there's plenty of room for improvement—like adding WebSocket support for smoother communication, better file handling, and expanding the list of tracked files.&lt;/p&gt;

&lt;p&gt;With just a few lines of Go code, I was able to improve the workflow for static web development, and I look forward to refining this tool even further.&lt;/p&gt;

&lt;p&gt;Check out the code: &lt;a href="https://github.com/abhiraj-ku/serve-It" rel="noopener noreferrer"&gt;serve-it GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>live</category>
      <category>extensions</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Building a bill splitting app - splitBhai (1/n) as a side project</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Sun, 15 Sep 2024 11:53:18 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/building-a-bill-splitting-app-splitbhai-1n-as-a-side-project-4p27</link>
      <guid>https://forem.com/abhishek_writes/building-a-bill-splitting-app-splitbhai-1n-as-a-side-project-4p27</guid>
      <description>&lt;h2&gt;
  
  
  Split Smart, Settle Easy - Simplifying Group Expenses
&lt;/h2&gt;

&lt;p&gt;Picture this: You’re out with your friends for dinner, or maybe you’re planning a weekend trip with your close-knit group. Everyone is having a great time, until it comes to splitting the bill. We’ve all been there—awkward calculations, someone forgetting to pay their share, and the inevitable “I’ll settle it later” promises. But what if splitting bills wasn’t a chore? What if it was fun, efficient, and even a little game-like?&lt;/p&gt;

&lt;p&gt;That’s where &lt;a href="https://github.com/abhiraj-ku/splitBhai" rel="noopener noreferrer"&gt;splitBhai&lt;/a&gt;comes in—a fresh take on managing group expenses that’s smarter, fairer, and way more fun &lt;/p&gt;

&lt;h2&gt;
  
  
  How did i got this idea to build a bill splitting app ?
&lt;/h2&gt;

&lt;p&gt;Well the answer is the two events that happened which let me think of a solution which could solve these two at a same time ( killing two birds with one stone kind of ..)&lt;/p&gt;

&lt;p&gt;The first event was when my friends and I went to Goa for a hackathon. And not just any hackathon—it was my very first one, and what better place than Goa, right? It was a six-day Web3 event (though, to be honest, I’m more of a backend and cloud guy) and it was fun until we got back  and saw my friends taking pen and paper to manually calculate all the expenses and i was like WTH ! Guys we have bill spliting apps why don't we use them (they find some apps trashy , not good UI).&lt;/p&gt;

&lt;p&gt;That was the first reason , now coming to second reason .. so we are college students and often times we struggle with not having some cash at month end so we ask our friends while going canteens/cafe along with them " hey you pay this time and i will write your assignment or any project submission thing"  and i thought hmm kind of barter system( i know not in truest sense but yes) wouldn’t it be cool if there were an app where people could exchange small favors like this? It’s not just about money; it’s about building relationships and creating a sense of community through these little gestures.&lt;/p&gt;

&lt;p&gt;and then's when i came up with the idea of making a bill splitting app with group bill sharing feature(so it eliminate manual bill sharing task) and small barter system kind of feature and came up with splitBhai (bro please split the bill and tell me my share of prices)&lt;/p&gt;

&lt;h2&gt;
  
  
  What Makes splitBhai Different?
&lt;/h2&gt;

&lt;p&gt;There are plenty of apps that split bills. But splitBhai takes things a step further with &lt;strong&gt;three game-changing features&lt;/strong&gt; that set it apart:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Debt Settlement with a Barter System&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Imagine being able to settle small debts not just with money, but with skills, favours, or shared resources. Did your friend pay for your movie ticket? Instead of transferring a few bucks, maybe you could repay them by picking them up from work or sharing your Netflix account for a month.&lt;/p&gt;

&lt;p&gt;This isn't just about keeping track of who owes what—splitBhai enables a &lt;strong&gt;barter system&lt;/strong&gt;, so you can settle debts in ways that fit your life. It’s about fostering stronger connections with your friends while solving the "I forgot to pay" problem in a creative way.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Saving Together as a Group&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Groups that spend together, save together! With splitBhai, you can create a monthly savings plan with your group. Each person contributes a little bit extra to a collective fund that can later be spent on group activities like weekend getaways, dinner parties, or any other shared experience.&lt;/p&gt;

&lt;p&gt;It’s like a mini-crowdfunding feature within the app! Not only does this save you from sudden large expenses, but it also ensures the group always has something fun planned ahead.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Gamified Debt Settlement&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Paying someone back doesn’t have to feel like a chore. splitBhai brings an element of &lt;strong&gt;gamification&lt;/strong&gt; into settling debts. Earn points for timely payments, or for paying in full without splitting hairs. Maybe you can even challenge your friends to pay their share faster by competing for group rewards. The more involved you are, the better your experience becomes.&lt;/p&gt;

&lt;h3&gt;
  
  
  It’s More Than Just an App
&lt;/h3&gt;

&lt;p&gt;At its core, splitBhai is about &lt;strong&gt;relationships&lt;/strong&gt;—whether it’s managing your group’s expenses, building trust through bartering, or contributing to group savings. Money is part of the equation, but it’s really about making life easier, fairer, and more fun when you’re navigating the sometimes tricky waters of group dynamics.&lt;/p&gt;

&lt;p&gt;And the best part? &lt;strong&gt;It’s open-source.&lt;/strong&gt; and i am excited to invite fellow developers, designers, and creative thinkers to join us in making splitBhai even better.&lt;/p&gt;

&lt;h3&gt;
  
  
  Want to Join Us on This Journey?
&lt;/h3&gt;

&lt;p&gt;So far, I’ve built a solid authentication and authorization system using &lt;strong&gt;JWT&lt;/strong&gt;, with support for &lt;strong&gt;email verification&lt;/strong&gt; (currently limited to Gmail addresses). Additionally, I’ve integrated &lt;strong&gt;Redis&lt;/strong&gt; for caching results and managing cookie expiration, which ensures better performance and security throughout the app. Also I am using MongoDB as primary Database , AWS for File storage and Deployment , Docker for Containerising the application for smoother deployment . Although Nothing has been done on the Front end part and that is why I am writing this Blog to Invite fellow developer who love building products.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s Build splitBhai Together!
&lt;/h3&gt;

&lt;p&gt;If this idea excites you, and even more so if you’re an Android developer, join the journey! This is just the beginning of &lt;em&gt;splitBhai&lt;/em&gt;. With your help, we can turn it into a solid, viable product. Let’s build something amazing together!&lt;/p&gt;

&lt;p&gt;Let’s bring a bit of joy back to group expense management—because managing money with friends shouldn’t be stressful, it should be fun. Come join us, and let’s make something amazing together!&lt;/p&gt;

&lt;p&gt;Github : &lt;a href="https://github.com/abhiraj-ku/splitBhai" rel="noopener noreferrer"&gt;https://github.com/abhiraj-ku/splitBhai&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Are you ready? Let’s go! 🚀&lt;/p&gt;

</description>
      <category>bills</category>
      <category>opensource</category>
      <category>sideprojects</category>
      <category>splitbills</category>
    </item>
    <item>
      <title>File handling 101 in Node Js</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Fri, 14 Jul 2023 14:53:39 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/file-handling-101-in-node-js-4di</link>
      <guid>https://forem.com/abhishek_writes/file-handling-101-in-node-js-4di</guid>
      <description>&lt;p&gt;if you have ever worked with programming languages like C++, Python or Java then you might have come across a term called "File handling". But If you are a Javascript Developer (which I assume if you are reading this blog), you might not have come across anything as such because there isn't support for File handling in Js. But what if there was a way to use Javascript code to perform file handling? Don't worry Node js has come to your rescue. Let's find out how&lt;/p&gt;

&lt;p&gt;Before moving forward we have to understand a few things like what is node js, how node js works &amp;amp;  what is asynchronous and synchronous code  . Having an understanding of these will help you not only with file handling but in general while working with node js as a backend developer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Node Js? And why is it important?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Node Js is a Runtime environment for javascript. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A runtime environment is a software framework that provides a platform for executing and running applications. It includes libraries, tools, and resources necessary for the execution of code written in a specific programming language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So what does this mean to you and me who are a javascript developer? Well, it means a lot. Earlier Developers used to write code in a file (index.js) and use a browser to execute our code. Because In those days Only browsers had a runtime environment to execute js code. Javascript was meant to be a scripting language for the Web and that too in the Front-end part. &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%2Fnv4kuzsj6bmoxq490vp6.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%2Fnv4kuzsj6bmoxq490vp6.PNG" alt="vanilla js" width="486" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But now With Node Js, you can run JS code in your local system and perform a lot of tasks. Also with Node js, you can write frontend as well as backend code using MERN (MongoDB, Express, React, Node) or MEAN (MongoDB, Express, Angular, Node). In simple terms, You can Become a full-stack developer using JS only (obviously there are a lot of things like HTML, CSS, database and a hell lot of things). &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%2F2bq6xso6id3q1cm9grj7.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%2F2bq6xso6id3q1cm9grj7.PNG" alt="node js " width="405" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Install Node JS?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To install Node, go to the Node js official site &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the 18.16.1 LTS version. It will automatically detect the OS you are using and give suggestions based on that &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install just like you install any other software keeping everything as default.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To check if Node is properly installed on your system or not, Open the terminal/command prompt and type: node -v. If you see the node version written there that means Node is properly installed on your system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now you can Write any js code Except the DOM manipulation as it is for browsers. Open the command prompt and type &lt;code&gt;console.log("Hello,World")&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You Have successfully executed your first node command(I know it's Js only ). Now that we have understood Node .let's understand Async and Sync code flow and why is it important in file handling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Async vs Sync code flow
&lt;/h2&gt;

&lt;p&gt;In Node.js, asynchronous (async) and synchronous (sync) operations refer to different approaches for executing code and handling I/O operations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous&lt;/strong&gt;: This type of code in Node.js block the execution of the program until the operation is completed. It means that each operation will have to wait for the previous one to finish before moving on to the next line of code. Here's an example of synchronous file reading in Node.js:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
// Synchronous file reading
try {
  const data = fs.readFileSync('test file.txt', 'utf8');
  console.log(data);
} catch (err) {
  console.error(err);
}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous&lt;/strong&gt;: It is completely opposite to sync operation. It does not block the program. It allows the program to continue its execution while the operation is being processed in the background . Async in file handling needs a callback function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
// Asynchronous file reading with callback
fs.readFile('file.txt', 'utf8', (err, data) =&amp;gt; {
  if (err) {
    console.error(err);
  } else {
    console.log(data);
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have understood the  prerequisites of File handling with Node js. let's go straight to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  File Handling in Node JS: Reading and Writing Files in Node.
&lt;/h2&gt;

&lt;p&gt;File handling in the node is possible due to a module called fs (file system). It provides all the necessary methods and functions to perform various operations, such as reading, writing, copying, updating, and deleting files. &lt;/p&gt;

&lt;p&gt;we will see the syntax of this and will discuss various methods one by one. Below is an example of the sync readFile method. we will see this in detail but for now, let's understand the syntax of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
// Synchronous file reading

  const data = fs.readFileSync('file.txt', 'utf8');
  console.log(data);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What are we doing here:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The code imports the built-in fs module, which provides file system-related functionality in Node.js.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The readFileSync a function is called to read the contents of the file named "file.txt".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the file reading operation is successful, the returned data is assigned to the data variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The contents of the file are then logged to the console using console.log(data)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Writing in files: Both Async and Sync operations
&lt;/h2&gt;

&lt;p&gt;Writing Files in sync flow: We can read files by using the fs module's &lt;code&gt;writeFileSync&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;you can easily retrieve the contents of a file and process them according to your needs. let us see the code implementation of this. As &lt;code&gt;writeFileSync&lt;/code&gt; a sync operation it requires two parameters, one is a file name with the proper file extension. For example, if it is a text file so the name will be &lt;code&gt;text.txt&lt;/code&gt; and next is the contents of the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fs.writeFileSync("./test.txt", "this is sync")   //sync writeFile op
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As soon as you type &lt;code&gt;node filename.js&lt;/code&gt; in the terminal, it will create a &lt;em&gt;test.txt&lt;/em&gt; file in your directory with the content that you have passed. In this case, is "this is sync". Remember this is a sync operation so it will block the other operations, so try to avoid using it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Writing File in Async flow&lt;/strong&gt;: In the async example, the WriteFile function initiates the file writing operation and immediately moves on to the next line of code without waiting for the operation to complete. Once the operation finishes, the callback function is invoked with the result or an error.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: this is an async operation so a callback function is necessary. Async operations are generally preferred in Node.js for I/O-intensive tasks since they allow the program to remain responsive and handle multiple requests simultaneously.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Reading File in sync way&lt;/em&gt;: This will have two params, One is a file name.txt and second is encoding (utf 8 for string )&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const readFile = fs.readFileSync("./test.txt", "utf8");
console.log(readFile)   //log the content of test.txt file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Reading File in async way&lt;/em&gt;: In this, it will have 3 params, filename, encoding, and callback function with two params which include error and data(you can call it anything) error will used to log if there is any error while reading the file and data is used to log the content of the file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fs.readFile("./test.txt", "utf8", (err, data) =&amp;gt; {
   if (err) console.log("Error :", err);  //log if any err found
  console.log(data);  //log the content in test file
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Appending the file&lt;/strong&gt;: Let's suppose you want to add some more content in the file but when you use the method discussed above it will over-write anything in it and add the new content in it. But we want to keep both of them so what should we do? There comes the append method which lets us add new content without overwriting the previous content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Synchronous File appending:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
// Synchronous file appending
fs.appendFileSync('file.txt', 'New data to append', 'utf8');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Async Append&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
// Asynchronous file appending
fs.appendFile('file.txt', 'New data to append', 'utf8', (err) =&amp;gt; {
  if (err) {
    console.error(err);
  } else {
    console.log('Data has been appended to the file successfully.');
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok so now that we have basic knowledge of how to read, write, and append files in both async and sync way and which way is best. We are good to go and explore file handling in node js.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: File handling in Node JS
&lt;/h2&gt;

&lt;p&gt;Congratulations! You've learned the fundamentals of file handling in Node.js. with the knowledge of the fs modules, you can confidently perform a variety of file operations, read and write data, and append data. By mastering file handling in Node.js, you'll unlock new possibilities for building robust web applications.&lt;/p&gt;

&lt;p&gt;This was my attempt to tell you about File handling in node js. I hope you have learnt something today. &lt;strong&gt;I write content related to Web Development so if this is your area of interest then you can subscribe to me. I will try my level best to bring more such content in future.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;If you are someone looking for a tech writer who can write content about Web Development, You can check my other blogs &lt;a href="https://dev.to/abhishek_writes"&gt;here&lt;/a&gt; . I am available to write content related to this topic.&lt;/em&gt;&lt;/strong&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%2Fomlhb4cgn3eyyzjju19n.gif" 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%2Fomlhb4cgn3eyyzjju19n.gif" alt="Conclusion on node js" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Connect with me on various Socials:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/abhishek-ko" rel="noopener noreferrer"&gt;&lt;em&gt;Linkedin&lt;/em&gt;&lt;/a&gt;: where I share things I am learning and building&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/abhirajabhi312" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;: I share my mind, and threads related to web dev daily. follow for valuable content there also.&lt;/p&gt;

&lt;p&gt;Check out my &lt;a href="https://github.com/abhiraj-ku" rel="noopener noreferrer"&gt;&lt;em&gt;GitHub&lt;/em&gt;&lt;/a&gt;, and the projects I am working on. I am a open source contributor also.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Understanding the const Keyword: With Array and Objects in Javascript</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Wed, 12 Jul 2023 09:46:34 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/understanding-the-const-keyword-with-array-and-objects-in-javascript-29dc</link>
      <guid>https://forem.com/abhishek_writes/understanding-the-const-keyword-with-array-and-objects-in-javascript-29dc</guid>
      <description>&lt;h2&gt;
  
  
  Understanding the const Keyword in Javascript
&lt;/h2&gt;

&lt;p&gt;Whether you're new to JavaScript or an experienced developer, you've likely come across the const keyword. It's a way to declare variables that hold constant values. Once you've declared a variable using const a keyword, you cannot assign it a new value. This makes const it ideal for situations where you want to ensure the immutability of a variable throughout your code.&lt;/p&gt;

&lt;p&gt;There are a lot of benefits of using the const keyword here are some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Predictability: Variables declared with const cannot be reassigned, ensuring their value remains constant&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;const restricts variable scope to the block scope where they are declared&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's understand with an example what happens when we re-assign values to a const variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = 10
console.log(a)  //output : 10
a=15;
console.log(a)  //output : TypeError: Assignment to constant variable.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But hey did I say that values declared with &lt;code&gt;const&lt;/code&gt; cannot be re-assigned? let's move further with our blog and understand why I chose to write "const is not constant". For this, we will see how const works with Arrays in js only then we will be able to understand this topic of mutability vs immutability &lt;/p&gt;

&lt;h2&gt;
  
  
  Data types in Javascript
&lt;/h2&gt;

&lt;p&gt;Before moving Further We have to know that there are two types of Data in Js, Understanding these data types is fundamental to working with JavaScript, as they influence how values are stored, manipulated, and interact with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primitive Data-types:&lt;/strong&gt; Number, String, Boolean, Null, Undefined, Symbol. If you know about these then well and good &amp;amp; if you don't, google them and read more about them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complex Data Types:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Object: Represents a collection of key-value pairs, where values can be of any data type, including functions and arrays.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Array: Represents an ordered collection of values, accessible by index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function: Represents a reusable block of code that can be invoked with specific parameters.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;let's deep dive more to understand the assigning and re-assigning of the const variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = 10;
a=15 
console.log(a); // Output: assignment error:cannot assign values to const 
b = a;
console.log(b); // Output: 10
b = 8;
console.log(b); // Output: 8
console.log(a); // Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Here's the breakdown of the code execution:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;const a = 10;: Variable a is declared and assigned the value 10 using const. a is a constant variable, and its value cannot be re-assigned.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;b = a;: The value of a (which is 10) is assigned to b. Since b is not explicitly declared using let or var, it becomes a global variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;console.log(b);: The value of b is logged into the console, which is 10 (the initial value assigned from a).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;b = 8;: The value of b is re-assigned to 8. As b is a global variable, in this case, it can be modified.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;console.log(b);: The new value of b, which is 8, is logged to the console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;console.log(a);: The value a remains unchanged and is still 10. const ensures that a it cannot be re-assigned.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have understood this, we are ready to understand the const keyword with arrays but Before that we some interesting things to tackle &lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Redeclaration &amp;amp; Reassignment
&lt;/h2&gt;

&lt;p&gt;We know that arrays in JavaScript are mutable, meaning their elements can be modified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr =[5,58,9,6,3]
console.log(arr)   //output: [ 5, 58, 9, 6, 3 ]
arr[1]=8      
console.log(arr)   //output: [ 5, 8, 9, 6, 3 ] This shows arrays are mutable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but what happens when we re-assign the value of the arr with new values using the Let declaration? let's see with code examples&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//re-assigning primitve data types
let a =15
a=18
console.log(a)  //output : 18 

//re-assigning complex data types
let arr =[5,58,9,6,3]
console.log(arr)    //output: [ 5, 58, 9, 6, 3 ]
arr=[8,6,96,53,12]
console.log(arr)     //output: [ 8, 6, 96, 53, 12 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;With the Let keyword let's understand these terms before moving forward&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redeclaration: It means changing the memory location of the variable which will throw an error. 
Note: re-declaration will not throw an error in the case of using var
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let s = 90
  let s=89
  console.log(s)  //SyntaxError:Identifier 's' has already been declared

  //using var keyword to redeclared

  var a = 90
  var a=89
  console.log(a)  //output : 89
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Re-assignment: It simply means changing the value of the variable without actually changing the memory allocation
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//re-assignment using let and var 

  let s = 90
   s=84
  console.log(s)      //output:84
  //var 
  var a = 90
   a=89
  console.log(a)      //output:89
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have understood the difference between these terms let's look at what happens when we apply these with const in complex data types&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the const keyword with arrays
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr =[5,58,9,6,3]
console.log(arr)
arr=[8,6,96,53,12]
console.log(arr)   //TypeError: Assignment to constant variable.

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

&lt;/div&gt;



&lt;p&gt;Why did this happen? As we know that &lt;strong&gt;once the array is declared with const a keyword it cannot be re-assigned even though we know that array is mutable&lt;/strong&gt;. So does that means we cannot change the values of the arr if we use the const keyword?&lt;/p&gt;

&lt;p&gt;let's look at another code to understand better&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//const is immutable but array is not 
const arr =[5,58,9,6,3]
arr[2]=10 
console.log(arr)    //output : [ 5, 58, 10, 6, 3 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;what just happened here. isn't this code suppose to return an error? how can an array with a const declaration is changed/updated? &lt;strong&gt;The answer to this is that const is immutable &amp;amp; It defines a constant reference to an array.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you know that &lt;strong&gt;complex data types are stored in a heap memory in the js engine&lt;/strong&gt;. when you do something like this (given below). Both the variable are referencing the same array and so if you make changes to one the other one will also be affected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr=[1,2,3]
abb=arr
abb.push(10)
console.log(abb)   //output:[ 1, 2, 3, 10 ]
console.log(arr)   //output:[ 1, 2, 3, 10 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but in the case of primitive data type when you do this same thing(given below) you will get a new variable and both the original and duplicate variable will have completely different reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a =10
let b= a
b= 18
console.log(b)    //output:18 
console.log(a)  //output : 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So when you do &lt;code&gt;const arr =[1,2,3]&lt;/code&gt; you are restricting the reference to this variable but you can still perform all the array methods but you cannot re-assign the complete new value to the const array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a =[1,2,3]
a.push(1,58)  //pushed new valued at the end of a
a.pop()       //removed the last value 
console.log(a)   //output :[ 1, 2, 3, 1 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I hope now you would have understood "why an array declared using const can still be modified". Understanding these things will make you a good JS developer and these things will be asked in the interview. So make sure you revise these topics well before your interviews.&lt;/p&gt;

&lt;p&gt;If you still have any doubts then you can use the comments section to ask your doubts. To understand JS from a more micro level I would recommend you a playlist called &lt;a href="https://www.youtube.com/playlistlist=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP" rel="noopener noreferrer"&gt;Namaste Javascript&lt;/a&gt; by Akshay Saini on Youtube he has some of the best js videos on the internet. Do check this playlist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Thanks once again if you have read till here.&lt;/em&gt;&lt;/strong&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%2Ffr2uunn66swj9wewjdv2.gif" 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%2Ffr2uunn66swj9wewjdv2.gif" alt="Const in javascript array" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect with me on socials :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/abhishek-ko" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/abhirajabhi312" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/abhiraj-ku" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Create and Publish a Package on NPM: A Step-by-Step Guide</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Sun, 09 Jul 2023 08:00:28 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/how-to-create-and-publish-a-package-on-npm-a-step-by-step-guide-53od</link>
      <guid>https://forem.com/abhishek_writes/how-to-create-and-publish-a-package-on-npm-a-step-by-step-guide-53od</guid>
      <description>&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%2Fihln0rmdmlncvzq711z1.gif" 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%2Fihln0rmdmlncvzq711z1.gif" alt="Package" width="600" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If You are into Software Development and you don’t know What is npm or a package? what are you even doing … But don’t worry by the end of this blog you will be able to understand What npm is, what is a npm package and How to make one for you and publish it so that others can also use it. Now Enough of this rant let’s get straight to the point and learn and understand for what you are here.&lt;/p&gt;

&lt;p&gt;First of what is &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;NPM&lt;/a&gt; and why you as a developer should know this? NPM Stands for Node Package Manager and as the name suggests it is a Package Manager for Javascript. It allows developers to easily install, manage and share Reusable codes called modules/packages to make applications efficiently.&lt;/p&gt;

&lt;p&gt;Let’s make an analogy with Google Play Store / Apple App Store to understand it even better. You use these stores to download any apps or games ( sometimes movies or books also ) or if you are a developer you can also upload your own apps/games onto these platforms for a fee. Now in the same way NPM is a store for Developers like you and me to install or share(publish) &lt;a href="https://www.npmjs.com/package/tweet-id" rel="noopener noreferrer"&gt;our codes&lt;/a&gt; in the form of modules or packages as we say.&lt;/p&gt;

&lt;h2&gt;
  
  
  But Wait why do we even need packages in the first place ?
&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%2Fz2z657lz4rymjzo90obv.gif" 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%2Fz2z657lz4rymjzo90obv.gif" alt="why npm package" width="360" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine a situation in which you are given the task of building a car (I know this is an extreme example, haha) so what will do? Are you going to build every part of the car from the engines to the structure of the car to the tires?&lt;/p&gt;

&lt;p&gt;No, Right because rather than reinventing the wheel we will import some parts and develop only crucial parts in-home so in the same way instead of writing code for everything from scratch we will use a package built by other devs so that we can focus on building important things on application. Plus it also provides a lot of features You can just google it and you will find a lot of articles/blogs explaining this.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what do we need to make/build a package from scratch?
&lt;/h2&gt;

&lt;p&gt;*&lt;em&gt;in order to make a package by yourself You need these 3 things :&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Node js - Node is the javascript runtime environment to run your javascript code locally on your system. To install this click &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;here&lt;/a&gt; and click on the option shown in the image below and rest just follow the steps like you install any other software.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After installing Open Terminal and type node -v. if you get something like v18.12.1 (this is the current version on my system) the node is properly installed on your system.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj1zf4wwp6xzfh5r3562.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%2Ftj1zf4wwp6xzfh5r3562.PNG" alt="Node JS" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;NPM - npm comes pre-installed with node. To verify do the same in the terminal, type npm -v. you will get 8.19.2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need some basics of Javascript &amp;amp; ES6 versions because we going to make this package in JS.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;**&lt;br&gt;
Now we are all set to make our first Package. next thing we need is to set up Our Project:**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a new directory for your project using mkdir project-name the command.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate into the project directory using cd project-name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialize the project as a Node.js project by running npm init command.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;During the initialization process, you'll be prompted to enter details such as the project name, version, description, entry point, test command, repository URL, and more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provide concise and accurate information for each prompt.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider using the default values for prompts that are not relevant or leave them blank.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use descriptive names and versioning following best practices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have set up these things next we need to write the code and Logic for our package. But Wait what are we gonna make? We are going to make A simple package that gives you the tweet id: &lt;a href="https://twitter.com/abhirajabhi312/status/1676605825446555650" rel="noopener noreferrer"&gt;https://twitter.com/abhirajabhi312/status/1676605825446555650&lt;/a&gt; (btw you can &lt;a href="https://twitter.com/abhirajabhi312" rel="noopener noreferrer"&gt;follow me&lt;/a&gt; on Twitter where I share my learning and thoughts) If you see the last thing in this URL is the id that we are talking about&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Setup your directory :&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make an index.js file and type the code of your package&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4bkw4knps8b51tvcheqs.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%2F4bkw4knps8b51tvcheqs.PNG" alt="NPM Package JS file" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our code ready let’s publish it on NPM.&lt;/p&gt;

&lt;p&gt;To publish your Package on NPM you need to have an account on npm. Go to NPM &amp;gt; sign up&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now Go to your project in vs code and open the terminal type ctrl+` (this is called the tilde sign ) and it will open a terminal screen for you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The first step is to type npm login in order to log in. It will then ask for your npm username, password and your registered email id. After entering the required information, npm will authenticate your credentials. To check type &lt;code&gt;npm whoami&lt;/code&gt; if your username is displayed that means you're logged in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now type npm publish . it will take some time depending on the size of the package. After some time you will see that your package is published along with your package details which have been provided during the setting up of your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To check go to npm and type your package name. You will see all the details of your package.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz7w8a5dn0yy5mqj65i5x.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%2Fz7w8a5dn0yy5mqj65i5x.PNG" alt="npm package website" width="800" height="313"&gt;&lt;/a&gt;&lt;br&gt;
This is the same package I uploaded on Npm. You can check &lt;a href="https://www.npmjs.com/package/tweet-id" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now that you have understood what is npm and how to make your very own npm package. Go ahead and make some cool packages that you think make other developers' life and easy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have made till here that means You now have all the knowledge in order to make your package and publish it on npm.&lt;/p&gt;

&lt;p&gt;I will try to post such useful content more in the future for now if you found this useful, don’t forget to share and subscribe to my newsletter. A Big Thank You &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%2F0qwdwtlgj6iyvmtc7szg.gif" 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%2F0qwdwtlgj6iyvmtc7szg.gif" alt="npm javascript package" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating your Chrome Extension: A Step-by-step Guide</title>
      <dc:creator>Abhishek Kumar</dc:creator>
      <pubDate>Sat, 08 Jul 2023 16:50:39 +0000</pubDate>
      <link>https://forem.com/abhishek_writes/creating-your-chrome-extension-a-step-by-step-guide-3f26</link>
      <guid>https://forem.com/abhishek_writes/creating-your-chrome-extension-a-step-by-step-guide-3f26</guid>
      <description>&lt;p&gt;if I ask you one question, have you ever used Grammarly or an Ad Blocker while browsing Chrome or for instance any browser like Firefox or Edge? Your answer would be yes, And what are they? They are called Extensions. So in this blog, I will guide you on how to make your Chrome extension from scratch.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is An Extension and why should we use them?
&lt;/h2&gt;

&lt;p&gt;Before we start coding, let us understand what is an extension. It is a small program written in HTML, CSS and javascript and interacts with the browser through API(Application Programming Interface) provided by that browser to add certain functionality like Adblocker or Password Manager to enhance your browsing experience.&lt;/p&gt;

&lt;p&gt;We can use them to customize or add functionalities that are not provided by the browsers. You Can find these extensions from the respective web stores of your browser for example &lt;a href="https://chrome.google.com/webstore/category/extensions" rel="noopener noreferrer"&gt;Chrome web store &lt;/a&gt;for Chrome, Add-ons for Firefox.&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%2F64kmmb710xynn3rb3633.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%2F64kmmb710xynn3rb3633.PNG" alt="Chrome Web store" width="492" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can choose an extension based on your specific needs like productivity, password manager, ad blocker, video speed controller and much more.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the things required to make an extension?
&lt;/h2&gt;

&lt;p&gt;Well in order to make an extension you need three things, let's discuss what are those things in brief:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Idea: What is your extension going to do, what will be its core features and functionalities? In this case, we going to make an extension whose only job is to remove any element on a website when we click on it. Let's call it Section Eraser&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, Set up a development folder: Create a dedicated folder on your computer to organize your extension's files. Name that folder as Section Eraser (you can give any name if you want, it is just that name defines what are we going to make)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basics of Html, CSS and javascript as these are things we will use to code our Chrome extension.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Coding our extension
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open vs code and navigate to your section eraser folder. Then Create these files:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;popup.html: This HTML file represents the user interface of your extension's popup window, which appears when users click on the extension's icon. This a very basic extension that has only one heading and a button, nothing fancy&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg84dm7xeq9r7xsf2zrlo.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%2Fg84dm7xeq9r7xsf2zrlo.png" alt="Html file" width="800" height="545"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Manifest .json file and why is so important while building your Chrome Extension?
&lt;/h2&gt;

&lt;p&gt;Next, we need to create a manifest.json file. This file is a crucial component when creating a Chrome extension. It serves as a configuration file that provides essential information about your extension to the browser.&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%2Funeqqa80ncswgqtzxp3e.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%2Funeqqa80ncswgqtzxp3e.png" alt="Manifest.json file" width="800" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;let's understand the core components of this file :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;manifest_version: Specifies the version of the manifest file format. Currently, the version is 3.&lt;/li&gt;
&lt;li&gt;name: The name of your extension.&lt;/li&gt;
&lt;li&gt;version: The version number of your extension.&lt;/li&gt;
&lt;li&gt;description: A brief description of what your extension does.&lt;/li&gt;
&lt;li&gt;icons: An object that defines the icons used for your extension in different sizes.&lt;/li&gt;
&lt;li&gt;permissions: An array that lists the permissions your extension requires, such as accessing tabs or specific websites. Specify the required permissions based on your extension's functionality.&lt;/li&gt;
&lt;li&gt;action: Specifies the behaviour of the extension's browser action (typically the icon displayed in the browser's toolbar).&lt;/li&gt;
&lt;li&gt;default_popup: The HTML file that serves as the popup window when the user clicks on the extension's icon.&lt;/li&gt;
&lt;li&gt;default_icon: An object that defines the default icon for your extension in different sizes&lt;/li&gt;
&lt;li&gt;scripts: An array of JavaScript files that make up the background script.&lt;/li&gt;
&lt;li&gt;background: Specifies the background script that runs in the background and handles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we need to create three .js files popup.js content.js and background.js These are our main js files where we will write all our logic and API to perform the desired action.&lt;/p&gt;

&lt;p&gt;let's start with a &lt;strong&gt;popup.js&lt;/strong&gt; file this will be our main file&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%2Fakfote611hfg4rclykej.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%2Fakfote611hfg4rclykej.png" alt="Javascript file" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;this code waits for the DOM to be fully loaded (DOMContentLoaded event) and then adds a click event listener to a button with the ID "select-button". When the button is clicked, it retrieves information about the active tab and sends a message to the content script in that tab, indicating that a section should be selected (the message payload { selectSection: true }). You can refer to the Chrome API developer section to know more.&lt;/p&gt;

&lt;p&gt;next is &lt;strong&gt;content.js&lt;/strong&gt; file Content scripts are JavaScript files that are injected into web pages by the browser when the extension is activated on specific web pages or matches certain URL patterns. In Our case, it is to detect a click event on a section of a website and then remove that section&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%2Fi2qgk4613iauhwttka1t.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%2Fi2qgk4613iauhwttka1t.png" alt="Javascript file" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next is the &lt;strong&gt;background.js&lt;/strong&gt; we have discussed this code so we are not going to discuss now&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%2Fm2e5r20roe2ia15ja9t8.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%2Fm2e5r20roe2ia15ja9t8.png" alt="Javascript file" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can add some styling to your extension. it's up to you. After that add some icons for your extension which have specific sizes like 16*16,48*48,128*128 and make sure they are jpg or png&lt;/p&gt;

&lt;p&gt;Now that we are done with the Coding part , let us check/test our extension but before moving forward let's have a look at our final folder 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%2Fxjshtra7cs7gqvxouyk4.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%2Fxjshtra7cs7gqvxouyk4.PNG" alt="Folder structure" width="354" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing our extension using the Chrome browser
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open Chrome browser and type chrome://extensions/ in your URL section. it will open the Chrome Extension page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs7c5yqwhsqr6bnhitoe4.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%2Fs7c5yqwhsqr6bnhitoe4.PNG" alt="Chrome Extension home page" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now Click on Developer Mode on the right side of the screen. it will give you three buttons as you can see in the above image&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now click on the Load unpacked button, It will open a popup screen asking you to upload your extensions folder containing all the files we have discussed. Upload them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After some time you will see your extension (see in the above image) on this page along with other extensions you have already installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To check, open any website, then click on your extension icon, it will then open your extension popup with a button, now click on that button, after that click on any section of that website and see the magic, it has removed that section&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: you can use this code to make your extension.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations! You've successfully learned the step-by-step process of creating a Chrome extension. Now go ahead and make some cool extensions and share it with others&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have made till here, Thank You for reading, Share and subscribe to get more content like this in future&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect with me on socials :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LinkedIn&lt;/p&gt;

&lt;p&gt;Twitter&lt;/p&gt;

&lt;p&gt;Github&lt;/p&gt;

</description>
      <category>chrome</category>
      <category>webdev</category>
      <category>extensions</category>
      <category>api</category>
    </item>
  </channel>
</rss>
