<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mukul Singhal</title>
    <description>The latest articles on Forem by Mukul Singhal (@mukul_singhal).</description>
    <link>https://forem.com/mukul_singhal</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%2F473225%2F9d0b2af8-2af4-4d89-8862-d2cc3a64abbf.jpg</url>
      <title>Forem: Mukul Singhal</title>
      <link>https://forem.com/mukul_singhal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mukul_singhal"/>
    <language>en</language>
    <item>
      <title>Deep Flatten an Array</title>
      <dc:creator>Mukul Singhal</dc:creator>
      <pubDate>Mon, 15 Nov 2021 20:13:21 +0000</pubDate>
      <link>https://forem.com/mukul_singhal/deep-flatten-an-array-5elf</link>
      <guid>https://forem.com/mukul_singhal/deep-flatten-an-array-5elf</guid>
      <description>&lt;p&gt;Hello all👋,&lt;/p&gt;

&lt;p&gt;In this series we will see a lot of question that are asked in javascript interviews so get ready for it&lt;/p&gt;

&lt;p&gt;In this article we will see How to flatten an deeply nested array for example&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[1,[2,3,[4,5]]] and convert in into [1,2,3,4,5]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will learn to flatten an array in 2 ways&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Using built in function (&lt;code&gt;flat()&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using recursion&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Using &lt;code&gt;Flat()&lt;/code&gt; method in Javascript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;flat()&lt;/code&gt; method is an inbuilt array method that flattens a given array into a newly created one-dimensional array. It concatenates all the elements of the given multidimensional array, and flats upto the specified depth.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var newArr = arr.flat(depth)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By default, the depth limit is 1. It can be 1 to &lt;code&gt;Infinity&lt;/code&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;arr&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]]];&lt;/span&gt;

  &lt;span class="c1"&gt;// Setting the depth value to&lt;/span&gt;
  &lt;span class="c1"&gt;// Infinity to deep flatten the array&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flattened&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;Infinity&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;flattened&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Output [1,2,3,4,5]&lt;/span&gt;



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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. Recursively flat an array (Pollyfill)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we will see how do it without using any builtin function or basically writing the pollyfill for flat function&lt;/p&gt;

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

&lt;span class="c1"&gt;//Flatten an array using recursion&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&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;flatten&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;// Output [1,2,3,4,5]&lt;/span&gt;



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

&lt;/div&gt;

&lt;p&gt;Let me explain the code&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Iterate through each and every value of an array and check whether it is value or an array using &lt;code&gt;Array.isArray()&lt;/code&gt;
method.&lt;/li&gt;
&lt;li&gt;If it is a value return it and concat it.&lt;/li&gt;
&lt;li&gt;If it is an array then follow again from step 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Using ES6 features (using &lt;code&gt;reduce()&lt;/code&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&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;flattened&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;flattened&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Output [1,2,3,4,5]&lt;/span&gt;




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

&lt;/div&gt;

&lt;p&gt;For better understanding of the code Please refer to the gif below.&lt;br&gt;
You can also check this &lt;a href="https://github.com/Mukul-Singhal/Javascript-interview-questions/blob/master/arrays/deeplyFlattenArray.js" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt; for the code&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%2Fi.imgur.com%2F6XdWH3v.gif" 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%2Fi.imgur.com%2F6XdWH3v.gif" alt="Recursion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila😃&lt;br&gt;
Let me know your thoughts about it 😃 and if you like it share it with others.&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%2Frk3yciobisco1ulfi03s.gif" 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%2Frk3yciobisco1ulfi03s.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to test Your API inside VSCODE</title>
      <dc:creator>Mukul Singhal</dc:creator>
      <pubDate>Fri, 07 May 2021 11:19:59 +0000</pubDate>
      <link>https://forem.com/mukul_singhal/how-to-test-your-api-inside-vscode-5635</link>
      <guid>https://forem.com/mukul_singhal/how-to-test-your-api-inside-vscode-5635</guid>
      <description>&lt;p&gt;Hey All 👋 . &lt;/p&gt;

&lt;p&gt;Recently I got to know about a VS Code extension called &lt;strong&gt;Thunder Client⚡⚡&lt;/strong&gt; which can be used to test our API inside VS Code.&lt;br&gt;
How Cool 😎 is that to test our API in the editor that we use all the time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thunder Client&lt;/strong&gt; is a GUI-based Rest Api HTTPS client and has a very clean UI and easy-to-use interface.&lt;/p&gt;

&lt;p&gt;One of the key highlights of this extension is &lt;strong&gt;Scriptless Testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As we need to write a lot of boilerplate code in Postman and other clients to do basic testing using scripting like status code equal 200. In Thunder client, there is a GUI-based test where we can select a couple of dropdowns to do most standard tests very easily without any scripting knowledge.&lt;br&gt;
As you can see in the image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AKe_upcoljKriEz1q6hmIHg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AKe_upcoljKriEz1q6hmIHg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🖥 How to install
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First of all open your VS Code and Click on extensions on the sidebar and install thunder client.&lt;/li&gt;
&lt;/ul&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%2F5ts7sjh59q6czrlnyws2.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%2F5ts7sjh59q6czrlnyws2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;now you will see a icon on side bar
&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%2Fri47g140gygip7v840pg.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lets test Thunder client a little bit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;for testing you can create your own API or you can use&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://gorest.co.in/" rel="noopener noreferrer"&gt;https://gorest.co.in/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and get your authentication token and you are good to go.&lt;/p&gt;

&lt;p&gt;below you can see Thunder Client in action in Below GIF&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET request
&lt;/li&gt;
&lt;/ul&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%2Fsfeerc57eueuxy8f40bo.gif" 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%2Fsfeerc57eueuxy8f40bo.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;POST request in which we create a GUI based Test&lt;/li&gt;
&lt;/ul&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%2Fauiegalj5rkgf9m6q4cj.gif" 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%2Fauiegalj5rkgf9m6q4cj.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can play around thunder client a little more.&lt;/p&gt;

&lt;p&gt;Let me know your thoughts about it 😃and if you like it share it with others.&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%2Fmedia2.giphy.com%2Fmedia%2F26AHC0kdj8IeLkmBy%2F200.webp%3Fcid%3Decf05e47a1atqwznh4fq0oe3xqf3hy4ifhr25jovp2c21ld7%26rid%3D200.webp%26ct%3Dg" 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%2Fmedia2.giphy.com%2Fmedia%2F26AHC0kdj8IeLkmBy%2F200.webp%3Fcid%3Decf05e47a1atqwznh4fq0oe3xqf3hy4ifhr25jovp2c21ld7%26rid%3D200.webp%26ct%3Dg" alt="end"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>vscode</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Must Know Trick for all the developers out there</title>
      <dc:creator>Mukul Singhal</dc:creator>
      <pubDate>Wed, 05 May 2021 20:13:29 +0000</pubDate>
      <link>https://forem.com/mukul_singhal/must-know-trick-for-all-the-developers-out-there-59ie</link>
      <guid>https://forem.com/mukul_singhal/must-know-trick-for-all-the-developers-out-there-59ie</guid>
      <description>&lt;p&gt;Hey All 👋, In this article I will show you a trick that will help all the developers out there.&lt;/p&gt;

&lt;p&gt;Many times we see a GitHub repository and want to work with it or want to add few minor changes to it and see how it works but for this, we clone the repository on our pc and start using it but we can simplify this process with a neat trick. &lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Just went to the repository you want to use.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/Mukul-Singhal/Flick" rel="noopener noreferrer"&gt;https://github.com/Mukul-Singhal/Flick&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1620244271221%2F20r2CDiDs.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1620244271221%2F20r2CDiDs.png" alt="github.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Put box after the gitHub in the url like this.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://githubbox.com/Mukul-Singhal/Flick" rel="noopener noreferrer"&gt;https://githubbox.com/Mukul-Singhal/Flick&lt;/a&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1620244279598%2FOvnYyiWkX.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1620244279598%2FOvnYyiWkX.png" alt="gitbox.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Press enter.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Ffy15h0tdeouqvvs9qfyn.gif" 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%2Ffy15h0tdeouqvvs9qfyn.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila 😁 now it opens in the code sandbox and you can use this repository in the codesandbox and make changes in it.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>github</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Write ES6 in Node using Babel</title>
      <dc:creator>Mukul Singhal</dc:creator>
      <pubDate>Sat, 27 Mar 2021 17:55:12 +0000</pubDate>
      <link>https://forem.com/mukul_singhal/write-es6-in-node-using-babel-3m7p</link>
      <guid>https://forem.com/mukul_singhal/write-es6-in-node-using-babel-3m7p</guid>
      <description>&lt;p&gt;Hi all 👋&lt;br&gt;&lt;br&gt;
In this short article, Today we will be learning about How to use ES6 syntax(like import from, export default, etc..) with NodeJs.&lt;br&gt;&lt;br&gt;
To use these ES6 syntaxes in node we will use &lt;a href="https://babeljs.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;Babel&lt;/strong&gt;&lt;/a&gt;. Now You are thinking what the heck is babel??&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Babel&lt;/strong&gt; is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backward-compatible version of JavaScript in current and older browsers or environments. &lt;br&gt;&lt;br&gt;
To understand what is babel and how to set it up I am taking a very simple example. You can use this setup for any NodeJs application(eg. for backend servers)&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Must have Nodejs installed on your pc.&lt;/li&gt;
&lt;li&gt;an editor of your choice. I prefer VSCode&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Let's start with the setup
&lt;/h3&gt;

&lt;p&gt;First of all, create a folder&lt;br&gt;
or &lt;br&gt;
on terminal write these command&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$ mkdir node_babel &lt;br&gt;&lt;br&gt;
$ cd node_babel&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;In this blog, we will create a very simple add function(sum.js) and export it in the main function(index.js)&lt;/p&gt;

&lt;p&gt;To initialize the project &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$ npm init   &lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;this will create a &lt;strong&gt;package.json&lt;/strong&gt; file for you&lt;/p&gt;

&lt;p&gt;Now create two files &lt;strong&gt;sum.js&lt;/strong&gt; and &lt;strong&gt;index.js&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$ touch sum.js index.js&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Install required Dependencies
&lt;/h2&gt;

&lt;p&gt;Now we will install babel and its dependencies. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$ npm install --save-dev  &lt;code&gt;@babel/core&lt;/code&gt; &lt;code&gt;@babel/cli&lt;/code&gt; &lt;code&gt;@babel/preset-env&lt;/code&gt; &lt;code&gt;@babel/node&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;--save-dev as it is a development dependency&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1616859773685%2FpFfcuCx7a.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1616859773685%2FpFfcuCx7a.png" alt="folder structure"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Folder Structure&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's understand about the following packages&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://babeljs.io/docs/en/babel-cli" rel="noopener noreferrer"&gt;&lt;strong&gt;@babel/cli&lt;/strong&gt;&lt;/a&gt; :- It is a built-in CLI that can be used to compile files from the 
command line.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://babeljs.io/docs/en/babel-node" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;@babel/node&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; :- babel-node is a CLI that works exactly the same as the Node.js CLI, with the added benefit of compiling with Babel presets and plugins before running it.

&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://babeljs.io/docs/en/babel-preset-env" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;@babel/preset-env&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; :- babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s).
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now also install nodemon as a development dependency&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$ npm i --save-dev nodemon&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After all these steps our package.json file looks like this &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1616862466740%2Fjce0uGLco.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1616862466740%2Fjce0uGLco.png" alt="carbon (1).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now create a file &lt;code&gt;.babelrc&lt;/code&gt; and put the following code in it.&lt;/p&gt;

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

{
  "presets": [
    "@babel/preset-env"
  ]
}


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

&lt;/div&gt;

&lt;p&gt;Now create an add function in &lt;code&gt;sum.js&lt;/code&gt; file and default export that function&lt;/p&gt;

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

//sum.js

function add(a, b) { 
  return a + b;
}

export default add; // ES6 export



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

&lt;/div&gt;

&lt;p&gt;Now  in &lt;code&gt;index.js&lt;/code&gt; import the add function and call it with the arguments&lt;/p&gt;

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

//index.js

import add from "./sum"; //ES6 import

console.log(add(3, 4)); //This should print 7 in the console



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

&lt;/div&gt;

&lt;p&gt;To run this code using babel we have to add a start script in the &lt;code&gt;package.json&lt;/code&gt; file&lt;/p&gt;

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

 "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1",
    "start": "nodemon --exec node_modules/.bin/babel-node index.js"
  }


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

&lt;/div&gt;

&lt;p&gt;Now on the command line run the following command&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$ npm start&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;in console, you will get this&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1616862667496%2FFvTqVs_84.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1616862667496%2FFvTqVs_84.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voilà  😃. Now if you have come to the end Congratulations you completed the NodeJs + Babel Setup&lt;/p&gt;

&lt;p&gt;I hope you find this blog useful. Do let me know your thoughts.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>babel</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
