<?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: Vivek Kumar</title>
    <description>The latest articles on DEV Community by Vivek Kumar (@vvkkumar06).</description>
    <link>https://dev.to/vvkkumar06</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%2F1072629%2F604e9acf-815a-46a7-aa6d-3b5a6f1ad0b4.jpeg</url>
      <title>DEV Community: Vivek Kumar</title>
      <link>https://dev.to/vvkkumar06</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vvkkumar06"/>
    <language>en</language>
    <item>
      <title>Exploring ReadableStream in the Browser: A Guide to Asynchronous Reading</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Thu, 25 Jan 2024 09:44:52 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/exploring-readablestream-in-the-browser-a-guide-to-asynchronous-reading-28g2</link>
      <guid>https://dev.to/vvkkumar06/exploring-readablestream-in-the-browser-a-guide-to-asynchronous-reading-28g2</guid>
      <description>&lt;p&gt;The &lt;code&gt;ReadableStream&lt;/code&gt; interface in the browser environment provides a standardized way to work with streams of data asynchronously. It is implemented by various classes and objects, offering a versatile set of options for handling data from different sources. In this article, we'll explore common classes and objects that implement the &lt;code&gt;ReadableStream&lt;/code&gt; interface, enabling you to perform asynchronous reading operations in your web applications. Additionally, we'll dive into using the &lt;code&gt;for await...of&lt;/code&gt; loop and async iterators to simplify the process of consuming data from these streams.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Fetch API: &lt;code&gt;Response.body&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;When making network requests using the Fetch API, the &lt;code&gt;Response.body&lt;/code&gt; property returns a &lt;code&gt;ReadableStream&lt;/code&gt; representing the body of the response. This allows you to asynchronously handle the data received from the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using for await...of loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &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;chunk&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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="nx"&gt;chunk&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;
  
  
  2. WebSocket API: &lt;code&gt;WebSocket&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The WebSocket API provides a &lt;code&gt;ReadableStream&lt;/code&gt; for receiving data from a WebSocket connection. This is particularly useful for real-time communication scenarios where data is sent and received continuously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;socket&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;WebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wss://example.com/socket&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readableStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using for await...of loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &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;message&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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="nx"&gt;message&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;
  
  
  3. File API: &lt;code&gt;Blob&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Blob&lt;/code&gt; object, representing a binary large object, implements the &lt;code&gt;ReadableStream&lt;/code&gt; interface. This is commonly used when working with files or binary data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blob&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;Blob&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, World!&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text/plain&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readableStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Using for await...of loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &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;chunk&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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="nx"&gt;chunk&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. Streams API: &lt;code&gt;ReadableStream.from&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The Streams API provides the &lt;code&gt;ReadableStream.from&lt;/code&gt; method, allowing you to create a readable stream from an iterable. This provides a convenient way to work with data from various sources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;iterable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readableStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReadableStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;iterable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Using for await...of loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &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;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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="nx"&gt;item&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;
  
  
  5. Server-Sent Events: &lt;code&gt;EventSource&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;EventSource&lt;/code&gt; API, used for handling Server-Sent Events, exposes a &lt;code&gt;ReadableStream&lt;/code&gt; for receiving events from the server. This is commonly used for establishing a unidirectional communication channel from the server to the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;eventSource&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;EventSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com/events&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readableStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;eventSource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using for await...of loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &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;event&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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="nx"&gt;event&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;
  
  
  6. File Input: File API
&lt;/h2&gt;

&lt;p&gt;When working with file input elements (&lt;code&gt;&amp;lt;input type="file"&amp;gt;&lt;/code&gt;), the selected file can be treated as a &lt;code&gt;Blob&lt;/code&gt; with a &lt;code&gt;ReadableStream&lt;/code&gt;. This allows you to asynchronously process the content of the selected file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fileInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fileInput&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fileInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readableStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Using for await...of loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &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;chunk&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readableStream&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="nx"&gt;chunk&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;In conclusion, the &lt;code&gt;ReadableStream&lt;/code&gt; interface opens up possibilities for handling asynchronous data streams in the browser. Whether you are fetching data from a server, working with WebSocket connections, processing files, or dealing with other iterable data sources, understanding these implementations of &lt;code&gt;ReadableStream&lt;/code&gt; empowers you to build more efficient and responsive web applications. Utilizing the &lt;code&gt;for await...of&lt;/code&gt; loop and async iterators further simplifies the consumption of asynchronous streams, making your code cleaner and more readable.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Advanced use of JavaScript toString() and parseInt()</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Thu, 25 Jan 2024 05:29:09 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/advanced-use-of-javascript-tostring-and-parseint-po6</link>
      <guid>https://dev.to/vvkkumar06/advanced-use-of-javascript-tostring-and-parseint-po6</guid>
      <description>&lt;p&gt;You might have been using toString() method and parseInt() in javaScript in day to day coding life.&lt;/p&gt;

&lt;p&gt;One basic use case is like converting a number to string with the help of toString() method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&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;n&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;//Output&lt;/span&gt;
&lt;span class="c1"&gt;//"10"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and converting a "10" to number using parseInt().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;//10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you know this means then you understand the basics of toString() and parseInt().&lt;/p&gt;

&lt;p&gt;Lets understand it further:&lt;/p&gt;

&lt;h2&gt;
  
  
  toString()
&lt;/h2&gt;

&lt;p&gt;When you use .toString()&lt;br&gt;
There is an optional parameter called base.&lt;/p&gt;

&lt;p&gt;You might have heard about number systems in Mathematics.&lt;/p&gt;

&lt;p&gt;The number system which we use in day to day life is decimal.&lt;/p&gt;

&lt;p&gt;A Decimal System uses 10 as base. We can represent it as &lt;br&gt;
25 -&amp;gt; 2x10^1 + 5x10^0&lt;/p&gt;

&lt;p&gt;I am assuming you understand above representation.&lt;/p&gt;

&lt;p&gt;There are few famous representations such as Hexadecimal, Octal and Binary. &lt;br&gt;
Hexadecimal - base 16&lt;br&gt;
Octal - base 8&lt;br&gt;
Binary - base 2&lt;/p&gt;

&lt;p&gt;I understand I moved away from the main agenda of this discussion. But the reason behind I was explaining about number system is we can use these bases to convert a number from one type to another.&lt;/p&gt;

&lt;p&gt;Lets say we need to convert "25" to binary&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&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="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
 &lt;span class="c1"&gt;// Output&lt;/span&gt;
 &lt;span class="c1"&gt;// 11001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or we want to convert "111" to hexadecimal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;111&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="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&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;// 6f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or we want to convert "43" to octal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;43&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="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&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;// 53&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There can be many use cases where you want to do these conversions one example is when you are dealing with buffer and you want to decode.&lt;/p&gt;

&lt;p&gt;Lets take another example,&lt;br&gt;
We want to convert text "Hello" to binary&lt;/p&gt;

&lt;p&gt;How we will do 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="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;char&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Output&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1001000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1100101&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1101100&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1101100&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1101111&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;If you add prefix to each no with 0b, you can use it with TypedArray View ( Uint8Array, Uint16Array or Uint32Array, etc)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unsignedArray&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;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0b1001000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0b1100101&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0b1101100&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0b1101100&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0b1101111&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use it as stream or convert it to blob.&lt;/p&gt;

&lt;p&gt;Again I don't want to go deep in Unit8Array. But just for understanding, we can use '0x' as hexadecimal, '0o' for octal.&lt;/p&gt;

&lt;p&gt;If you convert this to hexadecimal, then following will be the output&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="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0x&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;char&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&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;// [ "0x48", "0x65", "0x6c", "0x6c", "0x6f" ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I am sure, you must have seen these type of data specially while dealing with buffers.&lt;/p&gt;

&lt;h2&gt;
  
  
  parseInt()
&lt;/h2&gt;

&lt;p&gt;So, parseInt() method accepts first parameter as data we want to covert to integer and second optional parameter as base.&lt;/p&gt;

&lt;p&gt;Whatever data you pass inside parseInt() it will always try to convert it to a number or you can say to a decimal number to be exact that means its base will be 10.&lt;/p&gt;

&lt;p&gt;lets say we have a binary number 1001000 and we want to convert it to decimal. Then we can use parseInt()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1001000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// base 2&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;num&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;// 72&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and 72 is ASCII value of 'H'&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromCharCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;72&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;// 'H'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can experiment further and use it with other number system like hexadecimal.&lt;/p&gt;

&lt;p&gt;If you want to learn about ArrayBuffer, Uint8Array, Uint16Array, etc just comment below.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Uploading file in chunks from React to Node-Express</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Tue, 23 Jan 2024 16:12:58 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/uploading-file-in-chunks-from-react-to-node-express-3plf</link>
      <guid>https://dev.to/vvkkumar06/uploading-file-in-chunks-from-react-to-node-express-3plf</guid>
      <description>&lt;p&gt;In almost every web application we get some use cases where we need to upload files to server.&lt;br&gt;
One of the easiest way is using input type="file" and then sending to server as a blob.&lt;/p&gt;

&lt;p&gt;But sometimes sending files in chunks can be useful, for performance, security and other stuffs like showing upload completion percentage.&lt;/p&gt;

&lt;p&gt;In this tutorial we are going to upload a file from React application to Server in node and express.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 Setting up React App
&lt;/h2&gt;

&lt;p&gt;I am using &lt;a href="https://www.npmjs.com/package/react-formvik?activeTab=readme" rel="noopener noreferrer"&gt;react-formvik&lt;/a&gt; for quick form setup, I will create input type="file".&lt;/p&gt;

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

import React from 'react';
import { Form } from 'react-formvik';
const App = () =&amp;gt; {
    return &amp;lt;Form
        config={
            {
                fields: [
                    {
                        field: 'avatar',
                        css: {
                            containerClass: 'mt-4',
                            inputClass: 'form-control',
                            labelClass: 'form-label'
                        },
                        inputProps: {
                            type: 'file'
                        },
                        label: 'Upload'
                    }
                ],
                css: {
                    formContainerClass: 'container'
                }

            }
        }
        onChange={async ({ avatar }) =&amp;gt; {
           //We will add code here in further steps
        }
}

export default App;


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

&lt;/div&gt;

&lt;p&gt;I have also installed bootstrap to style our input field.&lt;br&gt;
Add below line in index.js or you can import it in css file as well.&lt;/p&gt;

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

import 'bootstrap/dist/css/bootstrap.css';


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Preview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkzwrkvfp03le1g1yshh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkzwrkvfp03le1g1yshh.png" alt="initial react preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Setting up server
&lt;/h2&gt;

&lt;p&gt;In express app, we need multer,&lt;br&gt;
&lt;code&gt;npm i -S multer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add following line in your server file&lt;br&gt;
const multer = require('multer');&lt;br&gt;
const storage = multer.memoryStorage();&lt;br&gt;
const upload = multer({ storage });&lt;/p&gt;

&lt;p&gt;Make sure you have body parser setup in express app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create one route for upload&lt;/strong&gt;&lt;/p&gt;

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

app.post('upload', (req, res) =&amp;gt; {
    //We will add code here in further steps
});


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 3: Understanding the approach of File chunking on Client
&lt;/h2&gt;

&lt;p&gt;So, we are going to follow below sub steps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we will click browse on UI and upload a file(image)&lt;/li&gt;
&lt;li&gt;In React component - in onChange method we will get file blob.&lt;/li&gt;
&lt;li&gt;We will keep one constant for chunk size (say: 1024 bytes) &lt;/li&gt;
&lt;li&gt;Knowing the chunkSize and file Size, we can find out how many chunks we need to create.&lt;/li&gt;
&lt;li&gt;We will create one loop and slice blob based on chunk size and in each iteration we will be sending next chunk to the server&lt;/li&gt;
&lt;li&gt;That means we are going to call server multiple times for the same route '/upload'.
&lt;strong&gt;For backend(node) approach we will discuss in upcoming steps.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 4: Implementing chunking in onChange method
&lt;/h2&gt;

&lt;p&gt;Now that we understand how we are going to implement we can start writing code.&lt;br&gt;
First we need to get file details in onChange event&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 onChange={async ({ avatar }) =&amp;gt; {
            const chunkSize = 1024;
            if (avatar) {
                  // we will proceed if we have files here
             }

}


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

&lt;/div&gt;

&lt;p&gt;Next, lets find out total chunks we need&lt;/p&gt;

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

 onChange={async ({ avatar }) =&amp;gt; {
            const chunkSize = 1024;
            if (avatar) {
                   const totalChunks = Math.ceil(avatar[0].size/chunkSize);
             }

}


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

&lt;/div&gt;

&lt;p&gt;Create a loop to iterate for each chunk&lt;/p&gt;

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

 onChange={async ({ avatar }) =&amp;gt; {
            const chunkSize = 1024* 100;
            if (avatar) {
                   const totalChunks = Math.ceil(avatar[0].size/chunkSize);

           for(let i=0; i&amp;lt;totalChunks; i++) {
                    const start = i*chunkSize;
                    const end = (i + 1) * chunkSize;
                    await sendChunk(start,end);
                }
             }

}


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

&lt;/div&gt;

&lt;p&gt;Lets create a sendChunk method to send chunk to server.&lt;/p&gt;

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

 onChange={async ({ avatar }) =&amp;gt; {
            const chunkSize = 1024;
            if (avatar) {
                   const totalChunks = Math.ceil(avatar[0].size/chunkSize);


                const sendChunk = async (start,end) =&amp;gt;{
                    const formData = new FormData();
                    const blobSlice = avatar[0].slice(start, end);
                    formData.append('file', blobSlice, avatar[0].name);
                    return await fetch('http://localhost:3000/upload', {
                        method: 'POST',
                        body: formData
                    });
                }
           for(let i=0; i&amp;lt;totalChunks; i++) {
                    const start = i*chunkSize;
                    const end = (i + 1) * chunkSize;
                    await sendChunk(start,end);
                }
             }

}


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 5: Implementing server
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

app.post('/upload', upload.single('file'), (req, res) =&amp;gt; {
    const { buffer, originalname } = req.file;
    const writeStream = fs.createWriteStream(originalname, { flags: 'a' });
    writeStream.write(buffer);
    writeStream.end();

    writeStream.on('finish', () =&amp;gt; {
        res.status(200).send('File received successfully.');
    });

    // Event listener for any errors during the write operation
    writeStream.on('error', (err) =&amp;gt; {
        console.error(err);
        res.status(500).send('Internal Server Error');
    });



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

&lt;/div&gt;

&lt;p&gt;Lets understand above code, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;upload.single('file') - is a middleware for multer which expects a form data with a file name 'file'&lt;/li&gt;
&lt;li&gt;In fs.createWriteStream we have added a flag 'a' which will actually append the buffer at the end of file every time it gets a request.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 6: Testing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft51ap7s4zlb0pu9uiw79.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft51ap7s4zlb0pu9uiw79.png" alt="Uploading an avatar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server console:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi1torcs56j14ow6kz9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi1torcs56j14ow6kz9d.png" alt="Server console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Network Requests:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpzdxw90bj24sjjwpfll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpzdxw90bj24sjjwpfll.png" alt="Network requests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Uploaded file:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feva0sc2j7ubsrparccds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feva0sc2j7ubsrparccds.png" alt="Uploaded file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There can be many other approaches, if you know one share with me as well.&lt;/p&gt;

&lt;p&gt;Thank you for reading this!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>node</category>
    </item>
    <item>
      <title>Understanding Buffer data in Node js</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Sun, 21 Jan 2024 06:01:03 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/understanding-buffer-data-in-node-js-4e0p</link>
      <guid>https://dev.to/vvkkumar06/understanding-buffer-data-in-node-js-4e0p</guid>
      <description>&lt;p&gt;I will keep this article short, the reason behind that is like, there can be so many questions you can explore yourself related to binary, buffer data, etc.&lt;/p&gt;

&lt;p&gt;In this tutorial, what I am going to do is, I will help you understand buffer data, how it gets created.&lt;/p&gt;

&lt;p&gt;In node js if you want to create one buffer, you can use one method called &lt;br&gt;
&lt;code&gt;Buffer.alloc(size)&lt;/code&gt;&lt;br&gt;
However, there are other ways as well as, which you can explore and comment below.&lt;/p&gt;

&lt;p&gt;So, when you create buffer, you can create something like this&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const buff = Buffer.alloc(8)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here &lt;strong&gt;8&lt;/strong&gt; is the size of buffer, means 8 bytes.&lt;br&gt;
1 byte = 8 bits &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;00000000 in binary &lt;/li&gt;
&lt;li&gt;00 in hexadecimal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you print buff in terminal you will see below output&lt;br&gt;
&lt;code&gt;&amp;lt;Buffer 00 00 00 00 00 00 00 00&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you notice we have 8 pairs of zeroes - that represent 8 bytes in hexadecimal.&lt;/p&gt;

&lt;p&gt;If you are a UI developer, you might be aware of hex color code where we use FF or AF or 3E etc, these are actually hexadecimal&lt;/p&gt;

&lt;p&gt;Lets take an example.&lt;/p&gt;

&lt;p&gt;We want to store "hello" in buffer. &lt;br&gt;
By looking at the word we can easily see, it has 5 characters.&lt;br&gt;
If we can store each character in 1 byte, we will need 5 bytes of buffer.&lt;/p&gt;

&lt;p&gt;Lets create a new buffer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const helloBuff = Buffer.alloc(5)
//output
&amp;lt;Buffer 00 00 00 00 00&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I told you each pair of zeroes represents one byte of hexadecimal number.&lt;/p&gt;

&lt;p&gt;So what we can do here is, we can transform each character of "hello" to hexadecimal number.&lt;/p&gt;

&lt;p&gt;To do that first we will have to convert it into it's ASCII value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'h' is 104 - 68 in hexadecimal
'e' is 101 - 65 in hexadecimal 
'l' is 108 - 6C in hexadecimal
'l' is 108 - 6C in hexadecimal
'o' is 111 - 6F in hexadecimal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To convert a decimal (say 108) to hexadecimal (say 6C ) follow below steps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Divide 108 by 16.&lt;/li&gt;
&lt;li&gt; Quotient: 6, Remainder: 12&lt;/li&gt;
&lt;li&gt; Continue dividing the quotient (6) by 16&lt;/li&gt;
&lt;li&gt; Quotient: 0 (Stop since the quotient is now zero). Remainder is 6&lt;/li&gt;
&lt;li&gt;Write in reverse order i.e. 6C ( here we can represent 12 as C in hex)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So our buffer data should be like&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Buffer 68 65 6C 6C 6F&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that we know what will be the output, we can test it now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helloBuff.write("hello");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to log helloBuff, your output will be same.&lt;/p&gt;

&lt;p&gt;You can also use toString() method to get proper values&lt;/p&gt;

&lt;p&gt;for e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helloBuff.toString('utf8'). //output - 'hello'
helloBuff.toString('base64') //output - 'aGVsbG8='
helloBuff.toString('hex') //output - '68656c6c6f'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to learn to calculate any string to base64 string. Please check my other article.&lt;br&gt;
&lt;a href="https://dev.to/vvkkumar06/converting-a-string-to-base64-manually-4ln2"&gt;https://dev.to/vvkkumar06/converting-a-string-to-base64-manually-4ln2&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Server Side Rendering Setup -2024</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Tue, 16 Jan 2024 16:01:42 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/react-server-side-rendering-setup-2024-1o30</link>
      <guid>https://dev.to/vvkkumar06/react-server-side-rendering-setup-2024-1o30</guid>
      <description>&lt;p&gt;In this tutorial we are going to setup development environment for React Server Side Rendering.&lt;/p&gt;

&lt;p&gt;We are going to use React v18, Webpack v5, React Router DOM v6 and Express v5.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Creating directory structure
&lt;/h2&gt;

&lt;p&gt;Create a project folder, I will name it 'react-ssr'.&lt;br&gt;
Initialize project with &lt;br&gt;
&lt;code&gt;npm init --yes&lt;/code&gt;&lt;br&gt;
Create a folder structure like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; src
 -client
 --index.js
 -server
 --index.js
 package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Create a basic express server
&lt;/h2&gt;

&lt;p&gt;If you have not used express js, that is fine, I will try to explain everything I will write here.&lt;/p&gt;

&lt;p&gt;Express js is node js framework, people mostly use it to create APIs.&lt;br&gt;
To get started, lets install express&lt;br&gt;
&lt;code&gt;npm i -S express&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To create a basic server, write below code in 'server/index.js'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
const app = express();

app.get('/', (req, res) =&amp;gt; {
  res.send('Hello React SSR');
});
app.listen(3000, () =&amp;gt; {
  console.log("Server is running on port: 3000");
})

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

&lt;/div&gt;



&lt;p&gt;Now, if you try to run below command&lt;br&gt;
&lt;code&gt;node src/server/index.js&lt;/code&gt;&lt;br&gt;
Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server is running on port:  3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your import doesn't work then add "type":"module" in package.json&lt;/p&gt;

&lt;p&gt;If you try to access &lt;strong&gt;localhost:3000&lt;/strong&gt;, you will see 'Hello React SSR'&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Using webpack to bundle server code
&lt;/h2&gt;

&lt;p&gt;For production, we need to bundle our code and transform it to standard javascript code. So we will write webpack configuration for server.&lt;/p&gt;

&lt;p&gt;Create a file "webpack/server.config.js"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src
webpack
-server.config.js
package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In server.config.js write below code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require('path');
const externals = require('webpack-node-externals');

module.exports = {
    target: 'node', // Since target is node not browser
    entry: "./src/server/index.js", 
    mode: 'production',
    output: {
        path: path.resolve(__dirname, '../dist'),
        filename: 'server.js'
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    externals: [externals()], // will not bundle node modules
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            }
        ]
    },
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;lets install dependencies for webpack&lt;br&gt;
&lt;code&gt;npm i -D webpack webpack-cli babel-loader webpack-node-externals&lt;/code&gt;&lt;br&gt;
Although we have a loader called 'babel-loader' for webpack but this will not work until we configure babel.&lt;br&gt;
For the basic setup of babel, create a file with name .babelrc&lt;br&gt;
and write following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "presets": [
        "@babel/preset-env",
        ["@babel/preset-react", { "runtime" : "automatic"}]
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets install babel now.&lt;br&gt;
&lt;code&gt;npm i -D @babel/core @babel/preset-env @babel/preset-react&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Script to bundle server code
&lt;/h2&gt;

&lt;p&gt;In package.json, write 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;"scripts": {
    "build:server": "webpack --config webpack/server.config.js",

  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are explicitly giving path of config, if we don't do that it will try to pick webpack.config.js from root directory and we don't have that.&lt;/p&gt;

&lt;p&gt;if you run "npm run build:server"&lt;br&gt;
it will create a dist folder in root directory and if you open that folder, you will find we have one file i.e. server.js with some minified code.&lt;br&gt;
And that minification is happening because we have given "mode " as production in webpack config.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Creating our first React Component
&lt;/h2&gt;

&lt;p&gt;Create a file App.jsx in 'src/client/App.jsx'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const App = () =&amp;gt; {
 return (
    &amp;lt;&amp;gt;
       This is our App component
    &amp;lt;&amp;gt;
  )
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Update server code to return html string
&lt;/h2&gt;

&lt;p&gt;Now we will be updating our server/index.js file as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import { renderToString } from 'react-dom/server';
import App from '../client/App';


const app = express();

//* - it will match every request
app.get('*', (req, res) =&amp;gt; {
    const html = renderToString(
            &amp;lt;App /&amp;gt;
    );
    res.send(
        `
    &amp;lt;!DOCTYPE html&amp;gt;
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;head&amp;gt;
        &amp;lt;meta charset="utf-8"&amp;gt;
        &amp;lt;title&amp;gt;SSR React App&amp;lt;/title&amp;gt;
      &amp;lt;/head&amp;gt;
      &amp;lt;body&amp;gt;
        &amp;lt;div id="root"&amp;gt;${html}&amp;lt;/div&amp;gt;
        &amp;lt;script src="/bundle.js"&amp;gt;&amp;lt;/script&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  `
    )
})

const port = process.env.PORT || 3000;

app.listen(port, () =&amp;gt; {
    console.log('Server is running on port: ', port);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;lets install react dependencies: &lt;br&gt;
&lt;code&gt;npm i -D react react-dom&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So here we are using &lt;strong&gt;renderToString&lt;/strong&gt;, this will transform component to string.&lt;/p&gt;

&lt;p&gt;If you have noticed, we are using bundle.js, which we don't have currently. bundle.js is the bundle file for the client, which we are going to put it in public folder and server it from there.&lt;br&gt;
Its ok if you didn't understand, this will be clear in next few steps:&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 7: Webpack config for Client code
&lt;/h2&gt;

&lt;p&gt;create a file webpack/client.config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require('path');

module.exports = {
    entry: "./src/client/index.js",
    mode: "production",
    output: {
        path: path.resolve(__dirname, '../public'),
        filename: "bundle.js"
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            }
        ]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you noticed, this will create bundle.js inside public folder.&lt;br&gt;
So, lets create a public folder in root directory.&lt;/p&gt;

&lt;p&gt;Also, on server I want to add a script while sending html string to client as shown below:&lt;br&gt;
 &lt;br&gt;
but how this bundle.js be available on /bundle.js.&lt;br&gt;
For that we will have to make 'public' folder as static folder for express.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const app = express();

app.use(express.static('public'));

app.get('*', (req, res) =&amp;gt; {
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8: Client hydration code
&lt;/h2&gt;

&lt;p&gt;In file src/client/index.js&lt;br&gt;
Write below lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { hydrateRoot } from 'react-dom/client';

import App from './App';

const domNode = document.getElementById('root');

hydrateRoot(domNode, 
    &amp;lt;App /&amp;gt;
);

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

&lt;/div&gt;



&lt;p&gt;How this hydration works?&lt;br&gt;
On initial request, server will send rendered html string, and in html string we will also send a script that will have a link of client side bundle. Once we open the response in browser, bundle.js code will execute hyration code, that will compare the root component and will to attach all the user interaction code such as even listener or hooks. From here on usually we will be using react router dom which actually doesn't refresh page, so all the navigation will be part of client side bundle.&lt;br&gt;
Every time we refresh our page, a request goes to server and that then server will do same thing as mentioned above&lt;/p&gt;

&lt;p&gt;Now, lets say we have a route on client something called&lt;br&gt;
localhost:3000/orders&lt;br&gt;
For first time if we open this url, request will be sent to server, since we are trying to hit server's endpoint, server will do all the process irrespective of what are adding at the end of url, here '/orders'.&lt;/p&gt;

&lt;p&gt;To use this endpoint and forward it to client, we will use StaticRouter.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 9: Setting up react router dom
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm i -D react-router-dom&lt;/code&gt;&lt;br&gt;
Update our server code as given below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { StaticRouter } from 'react-router-dom/server';
...
...
app.get('*', (req, res) =&amp;gt; {
    const html = renderToString(
        &amp;lt;StaticRouter location={req.url} &amp;gt;
            &amp;lt;App /&amp;gt;
        &amp;lt;/StaticRouter&amp;gt;
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And on Client side, update as given below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
import { BrowserRouter } from 'react-router-dom';
...
...
const domNode = document.getElementById('root');

hydrateRoot(domNode, 
&amp;lt;BrowserRouter&amp;gt;
    &amp;lt;App /&amp;gt;
&amp;lt;/BrowserRouter&amp;gt;

);
...

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

&lt;/div&gt;



&lt;p&gt;In App.js we can add few routes for some pages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Route, Routes } from "react-router-dom";
import Orders from "./pages/Orders";
import Products from "./pages/Products";
const App = () =&amp;gt; {

    return (
        &amp;lt;Routes&amp;gt;
            &amp;lt;Route path="/" element={&amp;lt;Orders /&amp;gt;} /&amp;gt;
            &amp;lt;Route path="/products" element={&amp;lt;Products /&amp;gt;} /&amp;gt;
        &amp;lt;/Routes&amp;gt;
    )
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 10: Update package json script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "build:client": "webpack --config webpack/client.config.js",
    "build:server": "webpack --config webpack/server.config.js",
    "build": "npm run build:client &amp;amp;&amp;amp; npm run build:server",
    "start:dev": "concurrently \"npm run build:server &amp;amp;&amp;amp; nodemon --exec babel-node src/server/index.js\"  \"npm run build:client -- --watch\"",
    "start": "npm run start:dev"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install nodemon and concurretly to keep watching changes and run multiple commands together.&lt;br&gt;
&lt;code&gt;npm i -D nodemon concurrently&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Try this out and comment out the problem you face.&lt;/p&gt;

&lt;p&gt;Instead of using renderToString, you can also use react streaming server api - renderToPipeableStream&lt;br&gt;
If you use renderToPipeableStream, then you will be able to lazy load things on UI.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Help me add more features / resolve issues in react-formvik</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Sun, 14 Jan 2024 03:18:50 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/help-me-add-more-features-resolve-issues-in-react-formvik-jb8</link>
      <guid>https://dev.to/vvkkumar06/help-me-add-more-features-resolve-issues-in-react-formvik-jb8</guid>
      <description>&lt;p&gt;Sometime back I created this React library for forms, which helps user to create dynamic forms easily.&lt;/p&gt;

&lt;p&gt;I am continuously working on it.&lt;br&gt;
Though, I also need people to support me on this by using it and report some issues and awesome features.&lt;/p&gt;

&lt;p&gt;This will give me enough motivation to work on it and continue building awesome libraries.&lt;/p&gt;

&lt;p&gt;Please try it out once at-least!&lt;br&gt;
If you don't have that much time, go through the docs and live examples and share your thoughts on Github issues or here.&lt;br&gt;
Feel free to put negative feedbacks, I learn from it.&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/react-formvik"&gt;https://www.npmjs.com/package/react-formvik&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks in Advance!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>React Webpack 5 Setup - Understand everything you need to know</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Fri, 12 Jan 2024 14:22:58 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/react-webpack-5-setup-understand-everything-you-need-to-know-3idp</link>
      <guid>https://dev.to/vvkkumar06/react-webpack-5-setup-understand-everything-you-need-to-know-3idp</guid>
      <description>&lt;p&gt;I know there are so many articles you can find online.&lt;br&gt;
What I am doing different here is I will explain the process and every line you write.&lt;/p&gt;

&lt;p&gt;So, we will use latest React 18+ version and Webpack 5.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Creating Project Directory
&lt;/h2&gt;

&lt;p&gt;Create an empty folder in your hard drive. Open it in your favorite editor. You can open integrated terminal or separate terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F57hnrgnj32j97tdbb0r7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F57hnrgnj32j97tdbb0r7.png" alt="Create Folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Initialize project with NPM
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm init --yes&lt;/code&gt;&lt;br&gt;
It will create a package.json file&lt;br&gt;
We used '--yes' to pre-fill all the required things in package.json. You can update the details later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Create source folder
&lt;/h2&gt;

&lt;p&gt;lets create a folder 'src' to hold all the components&lt;br&gt;
create two files index.js and App.jsx. &lt;br&gt;
I have used 'jsx', so that we know it is bundling jsx files as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flnbl6xqm4eq1mxou3ptr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flnbl6xqm4eq1mxou3ptr.png" alt="Index and app file creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Create a index.html file
&lt;/h2&gt;

&lt;p&gt;Create a 'public' folder in root directory, and create index.html file.&lt;br&gt;
This will be our template that will mount our react components.&lt;br&gt;
To mount our react root component, create a div with id 'root', although you can use any name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foqgh6f760hb26bk5oeda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foqgh6f760hb26bk5oeda.png" alt="index.html"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Install react and react-dom
&lt;/h2&gt;

&lt;p&gt;We are going to use 'react-dom/client' to create a root and mount our main component there.&lt;br&gt;
To write jsx syntax, we need react.&lt;br&gt;
&lt;code&gt;npm i -D react react-dom&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz93xnrci9tsofee47gv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz93xnrci9tsofee47gv9.png" alt="index.js setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Define our App component
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdywhqafqtpt18y0mqvdt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdywhqafqtpt18y0mqvdt.png" alt="App component"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Note - Don't forget to import it in index.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Although, we have written code for React but till now there is no way to compile jsx syntax and run this code in browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Setup babel
&lt;/h2&gt;

&lt;p&gt;Install babel core and babel presets&lt;br&gt;
&lt;code&gt;npm i -D @babel/core @babel/preset-env @babel/preset-react&lt;/code&gt;&lt;br&gt;
We will use babel to transform our jsx to code compatible with modern browsers.&lt;br&gt;
Create a file .babelrc - this is a configuration file for babel&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwtfzwilmsh5hbw7h8pp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwtfzwilmsh5hbw7h8pp.png" alt="babel config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Presets in babel are set of some functions that help in transforming code. &lt;br&gt;
&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env&lt;/strong&gt; - It has some set of methods which converts  es6 to standard Javascript.&lt;br&gt;
&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react&lt;/strong&gt; - It will transform React(jsx) code to javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Setup Webpack
&lt;/h2&gt;

&lt;p&gt;Even though we have done setup for babel, but still there is no way to merge multiple files and bundle it one file.&lt;br&gt;
To bundle our react code and inject it in html file as script, we will use Webpack.&lt;/p&gt;

&lt;p&gt;Create a file &lt;strong&gt;webpack.config.js&lt;/strong&gt; in root directory.&lt;br&gt;
First we need to define is entry and output.&lt;/p&gt;

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

module.exports = {
    entry: "",
    output: ""
}


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

&lt;/div&gt;

&lt;p&gt;After updating entry and output&lt;/p&gt;

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

const path = require('path');
module.exports = {
    entry: path.join(__dirname, 'src/index.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
     }
}


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

&lt;/div&gt;

&lt;p&gt;You can easily understand above code, where we have used standard node module &lt;strong&gt;path&lt;/strong&gt; to give path of '/src/index.js' as entry and '/dist/bundle.js' as output.&lt;/p&gt;

&lt;p&gt;Before we proceed, lets install webpack dependencies we need.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i -D webpack webpack-cli babel-loader html-webpack-plugin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I will explain each dependencies why we are using them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;webpack&lt;/strong&gt; - It is a main webpack library, without this our configuration will not work.&lt;br&gt;
&lt;strong&gt;webpack-cli&lt;/strong&gt; -It will allow us to use webpack commands, using this we can run our server and build our code. Otherwise we will not be able to execute our webpack configuration.&lt;br&gt;
&lt;strong&gt;babel-loader&lt;/strong&gt; - Loaders in webpack are responsible for transforming code, here babel-loader will use .babelrc configuration and transform our es6 and jsx code to standard and compatible javascript that will be supported by browsers.&lt;br&gt;
&lt;strong&gt;html-webpack-plugin&lt;/strong&gt; - In webpack, we can also configure some plugins, this plugin will use our html file as template and this will inject bundle.js as script in html.&lt;/p&gt;

&lt;p&gt;Lets use these libraries to configure it further.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Resolve Extensions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;resolve&lt;/strong&gt; is a special property in webpack configuration that tells webpack to read these extensions. If we don't define this, we will get error as "Unable to resolve App.jsx' or something like this. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsv8ywxxnpshmacvj14w6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsv8ywxxnpshmacvj14w6.png" alt="resolve extensions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that webpack knows it needs to resolve these two types of files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Configure Loaders
&lt;/h2&gt;

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

const path = require('path');

module.exports = {
    entry: path.join(__dirname, 'src/index.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            }
        ]
    }
}


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

&lt;/div&gt;

&lt;p&gt;Without a loader, we can not transform our code. To configure a loader we define it under &lt;strong&gt;module&lt;/strong&gt;. We can add many rules, each rule will have a loader.&lt;br&gt;
In above code, this will work for only js and jsx file and will exclude node_modules. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 11: Configure plugin
&lt;/h2&gt;

&lt;p&gt;If you remember we installed one plugin, &lt;strong&gt;html-webpack-plugin&lt;/strong&gt;. Now its time to use this.&lt;/p&gt;

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

   plugins: [
        new HtmlWebpackPlugin({ template: './public/index.html'})
    ]


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 12: Install and setup Dev server
&lt;/h2&gt;

&lt;p&gt;To setup dev server, lets install a dependency provided by webpack for dev server&lt;br&gt;
&lt;code&gt;npm i -D webpack-dev-server&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 devServer: {
        hot: true,  // hot reloading
        port: 3000,  // port on which server will run
        open: true // open browser automatically on start
    }


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

&lt;/div&gt;

&lt;p&gt;Add above properties. &lt;/p&gt;

&lt;p&gt;So our final configuration will be,&lt;/p&gt;

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

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: path.join(__dirname, 'src/index.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({ template: './public/index.html'})
    ],
    devServer: {
        hot: true,
        port: 3000,
        open: true
    }

}


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 13: Configure script to run our server.
&lt;/h2&gt;

&lt;p&gt;Add below scripts in package.json&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  "scripts": {
    "start": "webpack serve --mode development",
    "build": "webpack --mode production"
  },


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

&lt;/div&gt;

&lt;p&gt;After all these 13 steps, now its time to test our server&lt;br&gt;
Run below command in terminal&lt;br&gt;
&lt;code&gt;npm start&lt;/code&gt; this will open app in our default browser.&lt;br&gt;
&lt;code&gt;npm run build&lt;/code&gt; this will create a dist folder with bundle file.&lt;/p&gt;

&lt;p&gt;To avoid using in every file&lt;/p&gt;

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

import React from 'react';


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

&lt;/div&gt;

&lt;p&gt;update your .babelrc with below code&lt;/p&gt;

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

{
    "presets":[
        "@babel/preset-env",
        ["@babel/preset-react", {"runtime": "automatic"}]
    ]
}


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

&lt;/div&gt;

&lt;p&gt;If you noticed we have added { "runtime" : "automatic" }&lt;br&gt;
This will make React object globally available.&lt;/p&gt;

&lt;p&gt;At the end of this you will have two things,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Running server&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsy4io9fgif85j4d452o3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsy4io9fgif85j4d452o3.png" alt="running server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;build files&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn1s4jlnoj9fsst2clcul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn1s4jlnoj9fsst2clcul.png" alt="Build files"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope it was easier to understand, if something did not work comment it out.&lt;/p&gt;

&lt;p&gt;Happy Learning!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Setup rollup for React Library project - 2024</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Sun, 07 Jan 2024 16:41:21 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/setup-rollup-for-react-library-project-2024-3jea</link>
      <guid>https://dev.to/vvkkumar06/setup-rollup-for-react-library-project-2024-3jea</guid>
      <description>&lt;p&gt;In this tutorial, we will learn how we can setup our development environment for React Library Project.&lt;/p&gt;

&lt;p&gt;I will keep it very simple in steps and will try to explain as much as i can. &lt;br&gt;
I assume you must have node installed and you are already familiar with npm. &lt;br&gt;
Open your terminal in your project folder.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1 - Initializing npm package.
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm init --yes&lt;/code&gt;&lt;br&gt;
You can fill rest of things in package.json.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2 - Installing React dependencies
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once you will install you can find it in &lt;strong&gt;devDependencies&lt;/strong&gt; in package.json.&lt;br&gt;
But we don't need to bundle react and react-dom in our library considering the consumers will already be having these two.&lt;br&gt;
So, copy react and react-dom to &lt;strong&gt;peerDependencies&lt;/strong&gt;.&lt;br&gt;
By doing this it will be considered external library while bundling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"devDependencies": {

  },
  "peerDependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3 - Installing rollup
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D rollup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4 - Create a rollup config file in project
&lt;/h2&gt;

&lt;p&gt;Create a file with name rollup.config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default [
 //rollup configurations
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an array because we can add multiple configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 - Input configuration
&lt;/h2&gt;

&lt;p&gt;So the first thing we need do is let rollup know which file is our entry file.&lt;br&gt;
&lt;/p&gt;

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

export default [
    {
        input: './src/index.js',

    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6 - Output Configuration
&lt;/h2&gt;

&lt;p&gt;Next, we will define how our output files will look like and where it will reside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default [
    {
        input: './src/index.js',
        output: [
            {
                file: 'dist/index.js',
                format: 'cjs',
                sourcemap: true
            },
            {
                file: 'dist/index.es.js',
                format: 'es',
                exports: 'named',
                sourcemap: true
            }
        ]
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, I have added two output files, one in format of commonjs i.e. 'cjs' and another is ES6 i.e. 'es'.&lt;/p&gt;

&lt;p&gt;Using two different types of output in the Rollup configuration is a common practice when you want to provide your library in different module formats to cater to various use cases and environments. In this specific configuration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CommonJS (cjs) Format:
    File: dist/index.js
    Format: cjs (CommonJS)
    Sourcemap: Enabled (sourcemap: true)

CommonJS is a module format commonly used in Node.js environments. This format allows your library to be consumed by Node.js applications or projects that use bundlers compatible with CommonJS.

ECMAScript Module (es) Format:
    File: dist/index.es.js
    Format: es (ECMAScript module)
    Exports: Named exports (exports: 'named')
    Sourcemap: Enabled (sourcemap: true)

ECMAScript module format is the standard for modern JavaScript, and it is widely supported in modern browsers and other environments. Providing your library in this format allows developers to import it directly into projects that support ES modules.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The inclusion of source maps (sourcemap: true) also aids in debugging by mapping the bundled code back to the original source code.&lt;/p&gt;

&lt;p&gt;Now since we have defined input and output configurations, the next thing is how we will be transpiling our code from input to output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7 - Installing Babel
&lt;/h2&gt;

&lt;p&gt;Before we proceed, we will install basic libraries we need to transpile our react code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D babel-core babel-loader @babel/preset-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8 - Installing Rollup plugins
&lt;/h2&gt;

&lt;p&gt;Install these plugins as devDependencies &lt;br&gt;
@rollup/plugin-babel&lt;br&gt;
@rollup/plugin-node-resolve&lt;br&gt;
rollup-plugin-peer-deps-external&lt;br&gt;
@rollup/plugin-commonjs&lt;br&gt;
@rollup/plugin-terser&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9 - Configure rollup plugins
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';

export default [
    {
        input: './src/index.js',
        output: [
            {
                file: 'dist/index.js',
                format: 'cjs',
                sourcemap: true
            },
            {
                file: 'dist/index.es.js',
                format: 'es',
                exports: 'named',
                sourcemap: true
            }
        ],
        plugins: [
            external(),
            resolve({ extensions: ['.js', '.jsx'] }),
            commonjs(),
            babel({
                babelHelpers: 'bundled',
                exclude: 'node_modules/**',
                presets: [['@babel/preset-react', { "runtime": "automatic" }]],
                extensions: ['.js', '.jsx']
            }),
            terser()
        ]
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;lets understand line by line&lt;br&gt;
    &lt;strong&gt;external()&lt;/strong&gt;: Marks external dependencies to avoid bundling them. External dependencies should be resolved at runtime.&lt;br&gt;
    &lt;strong&gt;resolve({ extensions: ['.js', '.jsx'] })&lt;/strong&gt;: Resolves modules using Node.js resolution algorithm, and specifies the allowed file extensions for modules.&lt;br&gt;
    &lt;strong&gt;commonjs()&lt;/strong&gt;: Converts CommonJS modules to ES modules, allowing interoperability between CommonJS and ES module formats.&lt;br&gt;
    &lt;strong&gt;babel({ options })&lt;/strong&gt;: Transpiles JavaScript code using Babel. In this case, it includes presets for React (&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react) with automatic runtime ({ "runtime": "automatic" }).&lt;br&gt;
    &lt;strong&gt;terser()&lt;/strong&gt;: Minifies the bundled code using Terser, reducing its size.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is runtime: "automatic ?
&lt;/h2&gt;

&lt;p&gt;The "automatic" runtime in Babel refers to the new JSX transform introduced in Babel 17. This transform changes how JSX is compiled, and it eliminates the need for a global React import in each file that uses JSX.&lt;/p&gt;

&lt;p&gt;In earlier versions of Babel, when you used JSX in your code, Babel would automatically transform it into React.createElement calls. However, this transformation required a reference to the React object, so you had to include import React from 'react' at the top of each file using JSX.&lt;/p&gt;

&lt;p&gt;With the introduction of the automatic runtime in Babel 17, the need for the explicit React import is eliminated. Instead of injecting React.createElement calls directly into your code.&lt;/p&gt;

&lt;p&gt;This is all you need to get started with rollup for react.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Converting a string to Base64 manually</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Sun, 07 Jan 2024 05:57:24 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/converting-a-string-to-base64-manually-4ln2</link>
      <guid>https://dev.to/vvkkumar06/converting-a-string-to-base64-manually-4ln2</guid>
      <description>&lt;p&gt;As a web developer, you must have heard or even used Base64 encodings. Generally we convert some texts or urls to Base64 encoded string. To do this either, we use programming language's methods or we use some third party tools.&lt;/p&gt;

&lt;p&gt;In this tutorial we are going to learn how we can encode any text into Base64 manually.&lt;/p&gt;

&lt;p&gt;Lets say, we want to encode a text &lt;strong&gt;"hi"&lt;/strong&gt; in base64 binary encoding. Why I am saying it as binary, because base64 encoding is one of the binary representations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Text To ASCII ( text is "hi")
&lt;/h2&gt;

&lt;p&gt;First, each character in the string is converted to its ASCII representation, For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h: 104       i: 105     
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Convert each ASCII character to 8bit binary
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;01101000 01101001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Split these binary numbers into group of 6 bits.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;011010 000110 1001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Padding(if required)
&lt;/h2&gt;

&lt;p&gt;If you notice the least significant number doesn't have 6 bits, then add 0 (zeroes) at the end to make it 6bits&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;011010 000110 100100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Just remember one thing here,&lt;br&gt;
if we add two zeroes then we will be using "=" at the end of base64 string &lt;br&gt;
if we will add 4 zeroes then we will be using "==" at the end of base64 string&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5 Convert it to Decimal
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;26 6 36
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 6: Use Base64 Table to find out corresponding character encoding
&lt;/h2&gt;

&lt;p&gt;Base64 Table - it contains 64 characters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Value Encoding  Value Encoding  Value Encoding  Value Encoding
         0 A            17 R            34 i            51 z
         1 B            18 S            35 j            52 0
         2 C            19 T            36 k            53 1
         3 D            20 U            37 l            54 2
         4 E            21 V            38 m            55 3
         5 F            22 W            39 n            56 4
         6 G            23 X            40 o            57 5
         7 H            24 Y            41 p            58 6
         8 I            25 Z            42 q            59 7
         9 J            26 a            43 r            60 8
        10 K            27 b            44 s            61 9
        11 L            28 c            45 t            62 - (minus)
        12 M            29 d            46 u            63 _
        13 N            30 e            47 v           (underline)
        14 O            31 f            48 w
        15 P            32 g            49 x
        16 Q            33 h            50 y         (pad) =
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, &lt;br&gt;
26 -&amp;gt; a&lt;br&gt;
6 -&amp;gt; G&lt;br&gt;
36 -&amp;gt; k&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7 - Now add padding ( we added two zeroes, so we will use one equal(=) sign.
&lt;/h2&gt;

&lt;p&gt;aGk=&lt;/p&gt;

&lt;p&gt;You can also verify this with JavaScript method&lt;br&gt;
btoa("hi") . It will also print same.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>react-formvik - a highly customizable React Form Library</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Sat, 06 Jan 2024 16:43:59 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/react-formvik-a-highly-customizable-react-form-library-2en1</link>
      <guid>https://dev.to/vvkkumar06/react-formvik-a-highly-customizable-react-form-library-2en1</guid>
      <description>&lt;p&gt;Creating a form in React sometimes become tedious and we write a lot of code.&lt;br&gt;
You might have used so many third party libraries for the same.&lt;/p&gt;

&lt;p&gt;Recently, I developed a npm package &lt;a href="https://www.npmjs.com/package/react-formvik?activeTab=readme"&gt;react-formvik&lt;/a&gt;&lt;br&gt;
that allows a developer to create highly customizable React forms.&lt;/p&gt;

&lt;p&gt;Using react-formvik, you don't need to create form from scratch. Instead you can pick one of the available preset.&lt;/p&gt;

&lt;p&gt;For now I have provided 2 presets(login and register) in the library and in future I am planning to add more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Presets for Quick From Development&lt;/strong&gt;&lt;br&gt;
Using preset you just need to write few lines of code to create a form.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--22tPGUKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbe4xj078fbra47ecxth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--22tPGUKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbe4xj078fbra47ecxth.png" alt="Using login preset" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since our requirements won't be limited to just username or password, we can add more fields easily.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oKcuMU3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boerts3ruueex33riagd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oKcuMU3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boerts3ruueex33riagd.png" alt="injecting custom field" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jih2iaWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k17j7ulsn26e6pcmhd6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jih2iaWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k17j7ulsn26e6pcmhd6e.png" alt="Adding age code" width="800" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you notice above code, you will find we can add custom styles, we can add validation message, and also we can pass inputProps as we do in html input elements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also adjust order of injected field using property order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Styling&lt;/strong&gt;&lt;br&gt;
For styling you can simply add a css property in each field object and also you can add a global css property that will apply to all the fields&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   fields: [],
   css: {
        labelClass: 'form-label',
        inputClass: 'form-control',
        containerClass: 'mt-4 col-6',
        formContainerClass: 'row'
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Support of different Form Elements:&lt;/strong&gt;&lt;br&gt;
It supports almost all form elements including new html5 input types. There are things I still needs to add it in docs.&lt;br&gt;
You can easily create different input types, radio buttons, checkboxes, dropdowns etc. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validations&lt;/strong&gt;&lt;br&gt;
Adding validation in each field is very easy as you can add all the properties HTML elements accept for the validations.&lt;br&gt;
For example, required, min, max, pattern, minlength, maxlength, etc. You just need to pass everything in inputProps property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "fields": [
    {
      "label": "Website",
      "field": "url",
      "order": 1,
      "inputProps": {
        "type": "url",
        "pattern": "^(http://|https://)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?$"
      },
      "validation": {
        "errorMessage": "Please enter correct url!"
      }
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Bootstrap Support&lt;/strong&gt;&lt;br&gt;
By default, each preset supports bootstrap classes, means if you add bootstrap in your project, you will start seeing the styles of form element without adding any class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fascinating-paletas-04c303.netlify.app/?path=/docs/form--docs"&gt;&lt;br&gt;
Live Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will be working on the updates continuously. Feel free to add comments and suggestions. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>Javascript Object.groupBy(), an important method</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Fri, 29 Dec 2023 08:46:27 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/javascript-objectgroupby-an-important-method-482</link>
      <guid>https://dev.to/vvkkumar06/javascript-objectgroupby-an-important-method-482</guid>
      <description>&lt;p&gt;Most of the time we use some third party library like underscore or lodash, to group an array of objects based on some property.&lt;/p&gt;

&lt;p&gt;But did you know that we can also do this directly with JavaScript, since the JavaScript has a special method called .groupBy().&lt;/p&gt;

&lt;p&gt;groupBy() is a static method on Javascript 'Object'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yPOdQhPa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7xh3caugk5kwswtwz6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yPOdQhPa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7xh3caugk5kwswtwz6d.png" alt="Object properties" width="800" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets take an example-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const products = [
  { name: "asparagus", type: "vegetables", quantity: 5 },
  { name: "bananas", type: "fruit", quantity: 0 },
  { name: "goat", type: "meat", quantity: 23 },
  { name: "cherries", type: "fruit", quantity: 5 },
  { name: "fish", type: "meat", quantity: 22 },
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above products data, if you want to group data by it's type, then we can use groupBy() as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.groupBy(products, item =&amp;gt; item.type)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "vegetables": [
    {
      "name": "asparagus",
      "type": "vegetables",
      "quantity": 5
    }
  ],
  "fruit": [
    {
      "name": "bananas",
      "type": "fruit",
      "quantity": 0
    },
    {
      "name": "cherries",
      "type": "fruit",
      "quantity": 5
    }
  ],
  "meat": [
    {
      "name": "goat",
      "type": "meat",
      "quantity": 23
    },
    {
      "name": "fish",
      "type": "meat",
      "quantity": 22
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>coding</category>
    </item>
    <item>
      <title>Javascript .splice() vs .toSpliced()</title>
      <dc:creator>Vivek Kumar</dc:creator>
      <pubDate>Wed, 27 Dec 2023 15:00:32 +0000</pubDate>
      <link>https://dev.to/vvkkumar06/javascript-splice-vs-tospliced-3b78</link>
      <guid>https://dev.to/vvkkumar06/javascript-splice-vs-tospliced-3b78</guid>
      <description>&lt;p&gt;In this tutorial, we will learn how &lt;strong&gt;.toSpliced()&lt;/strong&gt; method can be handy. &lt;br&gt;
You might have used JavaScript array splice method.&lt;/p&gt;

&lt;p&gt;Lets have a look at how &lt;strong&gt;.splice()&lt;/strong&gt; works then we will understand how &lt;strong&gt;.toSpliced()&lt;/strong&gt; is different from it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Splice
&lt;/h2&gt;

&lt;p&gt;We can use splice when we want to remove some item from array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Below code example shows what happens when we remove array items using .splice().&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6sl0qomsqkoatzg6jh3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6sl0qomsqkoatzg6jh3e.png" alt="Removing items using splice"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Below code example shows what happens when we add array items using .splice()&lt;/em&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2mhejm3qspju733qo8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2mhejm3qspju733qo8p.png" alt="Adding items using splice"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One thing which is important to notice here is, arr.splice() always returns removed Items.&lt;br&gt;
You can also add and remove items at the same time but the output of arr.splice() will always be removed items.&lt;/p&gt;

&lt;p&gt;And it modifies the actual array.&lt;/p&gt;

&lt;h2&gt;
  
  
  toSpliced
&lt;/h2&gt;

&lt;p&gt;Array .toSpliced() also accepts the same parameter as .splice().&lt;br&gt;
But the first difference is it won't modify the original array instead it will return the updated array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Below code example shows what happens when we remove array items using .toSpliced().&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ie3ex79ljnccue49fui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ie3ex79ljnccue49fui.png" alt="removing items using .toSpliced()"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Below code example shows what happens when we add array items using .toSpliced()&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn6p1hwkv5ew1igtl8ypb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn6p1hwkv5ew1igtl8ypb.png" alt="adding items using toSplice"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
