<?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: Rudra Pratap</title>
    <description>The latest articles on DEV Community by Rudra Pratap (@merudra754).</description>
    <link>https://dev.to/merudra754</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%2F1076068%2F81089d73-18c8-4459-ab37-556a66ff175e.jpg</url>
      <title>DEV Community: Rudra Pratap</title>
      <link>https://dev.to/merudra754</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/merudra754"/>
    <language>en</language>
    <item>
      <title>Working with JS Array Indices</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Sun, 06 Aug 2023 20:43:04 +0000</pubDate>
      <link>https://dev.to/merudra754/working-with-js-array-indices-3dlj</link>
      <guid>https://dev.to/merudra754/working-with-js-array-indices-3dlj</guid>
      <description>&lt;p&gt;FUN FACT!!&lt;br&gt;
Array indices in Javascript can be integer, float or string!&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;let&lt;/span&gt; &lt;span class="nx"&gt;a&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="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;negative&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;float&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, -1: 'negative', 2.5: 'float']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How??&lt;/p&gt;

&lt;p&gt;Arrays in Javascript are just a special case of objects. That is, an array is just stored as an object behind the scenes.&lt;br&gt;
For example: &lt;br&gt;
&lt;code&gt;[ 1 , 2 ]&lt;/code&gt; is stored as &lt;code&gt;[ "1" : 1 , "2" : 2 ]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can access the array values not just using numberic index, but with strings too.&lt;/p&gt;

&lt;p&gt;That is:&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;let&lt;/span&gt; &lt;span class="nx"&gt;a&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will never get "Out of bound" exception in Javascript because,  arrays are not really arrays but objects in disguise.&lt;/p&gt;

&lt;p&gt;An object can have a maximum of 2^32 -1 properties (key-value pairs), which is the same as the maximum number of items an array can have.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Connecting Arduino to Internet using Websockets.</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Wed, 26 Jul 2023 12:28:26 +0000</pubDate>
      <link>https://dev.to/merudra754/connection-arduino-to-internet-using-websockets-2b3j</link>
      <guid>https://dev.to/merudra754/connection-arduino-to-internet-using-websockets-2b3j</guid>
      <description>&lt;p&gt;In this article I will be sharing a recent project that I made using arduino. &lt;/p&gt;

&lt;p&gt;Few years back, I made several arduino projects that used wireless communication using IR sensors and bluetooth. Though they worked perfectly but the only limitation was that the communcation range was not very great.&lt;/p&gt;

&lt;p&gt;I was always fascinated by controlling the microcontroller using internet, while researching I found that we need hardwares like Ethernet sheild, routers and static IP for client-server communication to make arduino webserver. &lt;/p&gt;

&lt;p&gt;Recently, I learnt about websocket protocol and socket.io library, and thought to connect my arduino with the internet and control its sensors.&lt;/p&gt;

&lt;p&gt;Since I had no ethernet sheild and router, it was impossible for me to establish direct communication between a browser and arduino. To resolve this issue, I decided to communicate with the arduino indirectly, ie via a remote server hosted on Render.com.&lt;br&gt;
In this solution, the client will establish websocket connection with the remote server. At the same time my arduino which is connected to nodejs server on localhost sending data via serialport, will also establish websocket connection with that remote server.&lt;/p&gt;

&lt;p&gt;The scenerio looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nET4sNKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9zqlxsduioq7gv5zh0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nET4sNKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9zqlxsduioq7gv5zh0m.png" alt="Image description" width="472" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For websocket connection, I used one of the popular libarary called Socket.io. It is a great libary for making realtime projects, and it is very easy to use too. &lt;/p&gt;

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

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

&lt;p&gt;In my project, browser and  nodejs localhost server were clients and the remote server was the main socket server.&lt;/p&gt;

&lt;p&gt;Since, I had established the realitime connection between the local machine and browser, I had to connect the arduino with the local machine so that it can control the sensors. &lt;br&gt;
In arduino we have the access to write on serial port. ie &lt;code&gt;Serial.println("turn on led")&lt;/code&gt;. We can access serial port in nodejs using a npm library called &lt;code&gt;serialport&lt;/code&gt;. With that, our whole problem is solved. Let me explain:&lt;/p&gt;

&lt;p&gt;We will send emit &lt;code&gt;lightOn&lt;/code&gt; message from the browser, this message will be catched by the remote server, then it will forward this message to the local nodejs server (remember, this local nodejs server is already connected to the remote server, because it is client with respect to it, and it had already established the connection). &lt;br&gt;
The local nodejs server will read the message, and accordingly write commands to the serial port. Since the arduino is already connected, it will read serial port and take necessary steps with the sensors. After performing tasks on the sensors, arduino will write acknowledgement signals to the serial port.&lt;br&gt;
Since the local nodejs server is continuously reading the serial port, as soon as it gets the acknowledgement, it will emit socket packet to the remote server conforming that the command has been fullfilled. The remote server will in turn report to the browser about the fullfillment of the command and the brower will update its UI accordingly.&lt;/p&gt;

&lt;p&gt;Below is the detailed diagram of the process involved in this process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://viewer.diagrams.net/?tags=%7B%7D&amp;amp;highlight=0000ff&amp;amp;edit=_blank&amp;amp;layers=1&amp;amp;nav=1&amp;amp;title=draw.io.drawio#R7RzbcqM49mtc3f2QFCCuj51kdntru7enkpnqnactGWSbCUYeEInTX79HIG5CxNgBnM2mq9qBgxDi3G9iga63%2B78neLf5RgMSLQwt2C%2FQzcIwdNN24A%2BHPBUQV9cKwDoJAzGoBtyFP4kAlsOyMCBpayCjNGLhrg30aRwTn7VgOEnoY3vYikbtp%2B7wmnQAdz6OutAfYcA24i0srYZ%2FIeF6Uz5Z18SVLS4HC0C6wQF9bIDQLwt0nVDKiqPt%2FppEHHklXor7%2FtZztVpYQmI25AbDvL81%2Fmn%2F%2BZP9Zbr2Pv7Pl99uLgR1HnCUiRcWi2VPJQZg3Tt%2B6GdL%2BHP1uAkZudthn8MegegA27BtBGc6HC5pFgck%2BLqsANi%2FXycc%2Bj1jURgTAQ9wcv8dpgkZ5wztUrPaQCOH8pGrMIquaUSTfD1ohQMH%2BwBPWULvSePK0rQtzYQr4qVIwsi%2BF1t6RQNgXkK3hCVPMETcYJUUFnyrO%2BL8seYC3bAK2KbBAa4YhwXjraupa9rAgSDPEaRyD5PqAG1wuitEZBXuSaDA7Gpl%2BByz6wQHISCqdS3wbFuF9cBe2pY9DtaR2ca6pXWxXiJ4FqTrSIF1O2KcV8MHOFyz%2FM0L0DKRIfDQ1jiJYIApJtEoCtcxHEdkxa9wbIagjT4L8DYMAn7zVULS8Cde5hNpcL6jYczyt7euFtYNnyljNC30qd6hW0y5ILYYQIBGoKKpSVQs5aRBRUNBRTQZFa1eKm70kjjfcMoIEFC7I8kDP6goWI8pgVnUoqP9V0Zz%2BtMkIMmFX2D0c%2F7E5OPFRRP%2BqZhG3CFPHIUjT3xLtpQRuOEb9jdc%2B9avxZ818dO%2FUMBpADfQGH5uCZiG5NKn23lX8S%2FwSv5MOf%2BRZUr9e8Jy%2ByzIncrk7q4IgJzig4V4qKyl3NTFawBY9dlvFNT2zYWh9RhbCqtdRbknsQFtQGKuDQqrK3TBCCJs21bb%2FKGuIkaaQoZ1YzIhVvkqshBfR9xuvRHZLV7mA%2BfcJfdkD3DpBLoDg6O95dojwAzn1M%2FptCS5P0sf41K02SbkywzIQ%2BjPrGNKkms%2B5isJ0zQjxe0hzdI8NNhucRzAoY23XILiZbprS%2Fe7yIPMobbVNt2zi3w5cUPkmypcxHwh58DBjpUP6ABBOodrlVCG89UCra2RqIbsNtWQ1fW1dHNOZ6t8hykDFdcnfYEKwRCPKAOVpWuZY6HdtV9ZoFIieUKs%2Bz6xVisVZpGNPBRMg9kqYXQ2zJqHMQvThLt0QHpEQqltOrbrcDiVom3%2BT4lq3UTWSDmOCrUC1Z7XRbVKdZiToVoVp70NVLuvDdX2dKjmCHXdqRWFZ70ylKIBKhgi4M88K80dkQinaei3Mdn26gATydO%2F%2BcmlVZ7%2BIUbmJzf75sibp5Y3SIJOalvCLfjtOFkTdtCudInQQLKlQHIJS0gELs9Dex0qzIsn%2FMp9rYbYoB4al1OkNEt8Iu6q6dedSJY%2FmQsKRHQmyhmheu0X8IYqjzgJb2gj8ca5SO4Zkv0%2FleSec4B3pib5EL9BRfIUFsaO4IRXT9E%2BN%2BNoiuraZSlIfdwxNVH7M8ncr1CmNviFiyJc5HkNQ9%2FtlYmMOxKnNEkbGYhiytFzEMNDYZXdHz3x4EqCqmtm15LbCv6cLIRFA2pto4gu2YesocPh7I%2FGlVqD85NSgU%2FvFBTyeNApGOI9nFXxuJ4n6wtHs050ILpz2Uiaa2LdU0rFS3QP6tE9n5MgC2N6uu55Bem1EVSRJ9WfXUXZQ1flQCcLKkxVNk2uenylgGgYVBW6BpQwd4qMdwfWTIHX6fsC8qORiY3LB6cRfsiLA2IBWpLFMc93izpBxFe6oSm7PFgkENn9IsebFxEZ5T8bPn%2Bneqc9hHmBolxUevIDcCkKWpYWK4dnhDl%2BdzRhz04rVQ0GYXo0s%2F56SwtyqG4qmmmUFn660oI1wDv3M%2BCtoDKtc0RnlUPQ5w44RuUq5De55dVfgUkBNVz3jm3unXMacVvyDpGsao%2BIHloTVSn7A%2BYbqI6fGsOEvRq%2BYF17dl22J42X%2B%2Fik8Y6mRkjveP3Z8XBQvOGovoqlSi%2BKJilZHQ51XnSjx3kh25AVQyLOft%2FjXjemAi%2BP0L%2BvwLWZpHLotVs8kKOoHKp8ncnCLqvb4fGjXe4FdEVph2TpY7iNcHxCotpbOXmla9qKliTgql4aQ1lYf86rFI%2B7Bd8Fx%2BuI1M%2BzJIFXtq6qNLZMWBwBv8eYkStu29IOfUfQE6XRV%2BiJF%2FfpaJL%2B8HrUx2SdKbnHKyum4S0oo6%2Bn1pPCx%2F3aUZfHNsLUXo9%2BWPqk3ta%2B7uMXdhg%2Fo1p6RVTKOSvyT%2FqsCSi7P%2Bp7i2JxS9IdjdOZG8dqcfDzFrLfdwHout%2F%2F8S4OcglG4RjMKw7GQMcAFnBVBexFtD6G25CndcXeJFM7lx%2Bhd9SUKow%2BukPvjTgS%2FRs13pTG7FjuM%2FoTtZhdPiYgQB8%2F5Pqcxh8%2BnUuTH2NQ3oYqL3TjUFWu6g5VqfLJ8tn2gMTAAD%2F1YPx%2BgGCNgBo546jnTt5nqLacDtf9OyZOT8K4Pcov4hn0N5Z2GYErPCn4V3WpzcsUp9a2h%2BS6XWQvmiXpS81EiwMZb352evL6YAn6rMlrOedsntz6Iid9ZRdrpOS1KxVAkTVDstj2jrEJ%2FSZ%2BRKNgWOOIvyPZX6TYJ6DcnjGZ%2FJdWaTz5HyqsZ6sgSUJYVRqPFUJ5X3NHmkcSQksWdmcGIXQGbNs51S40bQIYCcP5f7YJ1Q6tl9oEU5Mmmrmn2elmZRpqe5Ittr1e6unB%2FICqYm968G14uVMUF03Z7qlyiLNuS3T6E0QnB0O97XT6S5hk8LabQxv2AkzcVc82SYdgm2iqnITtu2S5GocNkNz4o%2FyMwJxcoGr7mYoLjHcuKBwwU%2Bo00LrKYF4u6O%2FiH58L0DsXFKHlgJ3q83LBBD1KvVxgvnNB4URLFgEpvg01Lxc8%2F1kZBcn5R%2BwuyrXlRIe1Waf5rTL79JWWqs7uC%2FhfNetrzSrodeNrGFpVGCp%2BF%2FzjS9XHXK7pdpvF4GQWgw%2FxZbN3%2FJz%2B7Bj%2BiNzz1nVHqm2DqtBv%2FI%2F6vXxPh2718AyQOWuQWauUW1KOYBuI2NebRafFXft4%2Ff0b%2BtTLG%2F9jYY03UlTjSF%2FFsocW4E%2FgHzitvw1ahOz1F1bRL%2F8F"&gt;diagram link&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hwQ6uWF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnuzvhvub0tmldol5gcz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hwQ6uWF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnuzvhvub0tmldol5gcz.png" alt="Image description" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>arduino</category>
      <category>webdev</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Customize your VSCode IDE</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Tue, 18 Jul 2023 05:26:43 +0000</pubDate>
      <link>https://dev.to/merudra754/customize-your-vscode-ide-2pp</link>
      <guid>https://dev.to/merudra754/customize-your-vscode-ide-2pp</guid>
      <description>&lt;p&gt;Vscode is a greate IDE, and it is the first choice of many developers. In this article I will share tips you can use to be more productive with Vscode.&lt;/p&gt;

&lt;p&gt;Many times we work with mulitple windows of Vscode, for example, while developing a fullstack web app, you have a window for frontend and another for backend. In that scenerio if often happens that you accidently messup with the code and write it on wrong folder, or just search a file which is not present in that folder.&lt;/p&gt;

&lt;p&gt;We can customize Vscode from its settings, but we don't want the changes to be reflected in all of our Vscode instances. We want the changes to persist on specific instances.&lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;code&gt;.vscode&lt;/code&gt; folder in project's root.&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;settings.json&lt;/code&gt; file in it.&lt;/li&gt;
&lt;li&gt;Customize the looks according to the following image reference.&lt;/li&gt;
&lt;/ol&gt;

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

</description>
      <category>vscode</category>
      <category>productivity</category>
    </item>
    <item>
      <title>PracticeHero.site : My new project!</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Fri, 14 Jul 2023 16:01:32 +0000</pubDate>
      <link>https://dev.to/merudra754/practiceherosite-my-new-project-3d98</link>
      <guid>https://dev.to/merudra754/practiceherosite-my-new-project-3d98</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eqb_lSfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://im3.ezgif.com/tmp/ezgif-3-4e93d97386.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eqb_lSfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://im3.ezgif.com/tmp/ezgif-3-4e93d97386.gif" alt="Image description" width="600" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hi friends, in this blog I will share about a project I have built recently.&lt;/p&gt;

&lt;p&gt;I often give virtual contests on Leetcode and other platforms to improve my DSA skills. &lt;br&gt;
With every contest I learnt new tricks and concepts. Very soon I realized that I was doing something wrong, ie I was not writing about my learnings, the new concepts, tricks and new algorithms anywhere. It often happens that you found some nice articles, blogs, videos or anyother resource regarding a topic and you save them somewhere but after some time you forget about it. &lt;br&gt;
This was happening with me too. &lt;/p&gt;

&lt;p&gt;One day I thought to make an application where I can save all the learnings and resources after giving a virtual contest on a coding platform, and track my progress. Then I developed PracticeHero.&lt;br&gt;
This web app serves a very niche area but indeed it is very useful. It is has a clean UI/UX. &lt;/p&gt;

&lt;p&gt;If you are a person who give virtual contests on various coding platforms, then you must check it out once!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.practicehero.site/"&gt;www.practicehero.site&lt;/a&gt;&lt;/p&gt;

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

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

&lt;p&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5hcvwtMm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2q6ci862i83qb0m0rt8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5hcvwtMm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2q6ci862i83qb0m0rt8t.png" alt="Image description" width="800" height="367"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>productivity</category>
    </item>
    <item>
      <title>HTTP vs WebSockets</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Sat, 08 Jul 2023 14:28:23 +0000</pubDate>
      <link>https://dev.to/merudra754/http-vs-websockets-complete-guide-478h</link>
      <guid>https://dev.to/merudra754/http-vs-websockets-complete-guide-478h</guid>
      <description>&lt;h2&gt;
  
  
  HTTP
&lt;/h2&gt;

&lt;p&gt;Whenever you type any URL in the browser, say &lt;code&gt;https://google.com&lt;/code&gt; and hit enter, a request goes to the DNS server in order to get the IP address behind the domain name. &lt;br&gt;
When the client gets the IP address, it establishes a TCP connection with the server on the cloud.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UKzhKf7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1k65z2yfoy2vq7ngf2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UKzhKf7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1k65z2yfoy2vq7ngf2w.png" alt="Image description" width="607" height="261"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP is based on client-server architecture, ie client requests for some data from the server, the server responds and then the connection is terminated. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hm7ldbI4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0p41pnwjtinx6ekyr2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hm7ldbI4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0p41pnwjtinx6ekyr2u.png" alt="Image description" width="708" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP is stateless. ie every time client wants to send data to server, it has to explicitly specify all the headers like cookie, authorization etc headers, so that the server can recognize it.&lt;br&gt;
Benefit of being stateless is that the request by the client can be served by any server in our backend as there is no state established among the server and the client. This enables us to easily scale the system horizontally.&lt;/p&gt;

&lt;p&gt;HTTP connections start with &lt;code&gt;http://yoursite.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;HTTP is an application layer protocol built on the top of TCP/IP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Websockets
&lt;/h2&gt;

&lt;p&gt;The Websocket protocol is stateful. It also used TCP under the hood. &lt;br&gt;
Here, the connection is not terminated after request-response process, but it exist until one of the party has not closed the connection explicitly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3lL3bHkb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lh1drk5w3ci0wm11phc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3lL3bHkb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lh1drk5w3ci0wm11phc.png" alt="Image description" width="671" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Websockets have low-latency, that is why they are used for realtime communication, chat applications, gaming etc.&lt;/p&gt;

&lt;p&gt;Websocket connections start with &lt;code&gt;ws://yoursite.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Drawback: If a connection is established, we can't transfer the next request to other server because if we do so the state will be lost. Hence it creates problems while scaling.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>How to showcase your projects?</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Fri, 07 Jul 2023 15:09:54 +0000</pubDate>
      <link>https://dev.to/merudra754/how-to-showcase-your-project-d46</link>
      <guid>https://dev.to/merudra754/how-to-showcase-your-project-d46</guid>
      <description>&lt;p&gt;If anybody asks about your projects you probably send him the live link of your project. A deployed project with a live URL is a good way to introduce your project, but it is not the best one.&lt;/p&gt;

&lt;p&gt;In this article, I will be writing about the important steps required to showcase your projects to a reviewer/recruiter. &lt;/p&gt;

&lt;h2&gt;
  
  
  System Design Documents
&lt;/h2&gt;

&lt;p&gt;You can document the important steps/algorithms you implemented while building your project. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What problems did you face? How did you solve them?&lt;/li&gt;
&lt;li&gt;What technologies/frameworks did you use?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architectural/System Design Diagrams
&lt;/h2&gt;

&lt;p&gt;Diagrams speak more that words!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can use UML or any online tool like draw.io.&lt;/li&gt;
&lt;li&gt;Diagrams help vizualize your app's architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  UX/UI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A good user experience is very important.&lt;/li&gt;
&lt;li&gt;No matter how performant, low latency your app has, it is not useable if it has poor UI. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Papers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can write a proper paper on which type of problem your application is going to solve.&lt;/li&gt;
&lt;li&gt;It is not necessary for everybody because it requires a lot of research.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Blog Articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Write blogs on platforms like Medium, Dev etc.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write about anything you know.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pick a problem, write about the problem, what did you do solve the problem, what was your approach?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Videos
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create videos of your product.&lt;/li&gt;
&lt;li&gt;Talk about it in the video.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Vertical Scaling vs Horizontal Scaling</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Fri, 07 Jul 2023 12:20:21 +0000</pubDate>
      <link>https://dev.to/merudra754/vertical-scaling-vs-horizontal-scaling-fch</link>
      <guid>https://dev.to/merudra754/vertical-scaling-vs-horizontal-scaling-fch</guid>
      <description>&lt;h2&gt;
  
  
  Vertical Scaling
&lt;/h2&gt;

&lt;p&gt;Vertical scaling is accomplished by upgrading the hardware. It is often the simplest solution for short term scalability, as it doesn't require any architectural changes to your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ways to scale vertically&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improving I/O access by switching to SSDs.&lt;/li&gt;
&lt;li&gt;Reducing I/O operations by increasing RAM.&lt;/li&gt;
&lt;li&gt;Improving network throughput by upgrading network interfaces. → if the server is streaming a lot of video/media content.&lt;/li&gt;
&lt;li&gt;Switching to servers with more cores or processors. : more cores → less CPU context switches&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have to upgrade the hardware only.&lt;/li&gt;
&lt;li&gt;You do not have to rearchitect anything.&lt;/li&gt;
&lt;li&gt;Perfect for small applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Limitations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vertical scaling becomes extremely expensive beyond a certain point.&lt;/li&gt;
&lt;li&gt;After a certain limit, hardware upgradation is not possible.&lt;/li&gt;
&lt;li&gt;OS limitations: lock contention bottleneck.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Horizontal Scaling
&lt;/h2&gt;

&lt;p&gt;Horizontal Scaling is used to distribute the traffic among many servers.&lt;/p&gt;

&lt;p&gt;We can add as many servers as we need. There is no upper limit as it was in vertical scaling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BddqyNxY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bbhanvm7lhj9xmz5x7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BddqyNxY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bbhanvm7lhj9xmz5x7e.png" alt="Image description" width="595" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>design</category>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Private static members in Javascript</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Wed, 05 Jul 2023 09:49:20 +0000</pubDate>
      <link>https://dev.to/merudra754/private-static-members-in-javascript-17h9</link>
      <guid>https://dev.to/merudra754/private-static-members-in-javascript-17h9</guid>
      <description>&lt;p&gt;In conventional object oriented programming languages like C++ and Java, we have a reserved keyword &lt;code&gt;private&lt;/code&gt; which is used to create private members of a class. But the scenerio is very different in the case of Javascript, where there is no keyword like &lt;code&gt;private&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Consider the following example&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;Book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isbn&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ISBN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;isbn&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getISBN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`ISBN number is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ISBN&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;book1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ISBN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;987&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getISBN&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// ISBN number is 987&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we can see that ISBN number can be easily manipulate from outside of the &lt;code&gt;Book&lt;/code&gt; constructor function.&lt;/p&gt;

&lt;p&gt;Thus there is no encapsulation and data hiding, which is very important for loose coupling, code maintainability and better management of code.&lt;/p&gt;

&lt;p&gt;Now, how can we create private members such that they can be accessible inside the constructor function only?&lt;/p&gt;

&lt;p&gt;The answer is : Closures&lt;br&gt;
Javascript provides the concept of closures, which means functions can access the environment in which they were defined, not the environment in which they are called. &lt;/p&gt;

&lt;p&gt;Look at the code example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isbn&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;ISBN&lt;/span&gt; &lt;span class="c1"&gt;// private attribute&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;checkISBN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;// private method&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;!==&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;  
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setISBN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;checkISBN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isbn&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Incorrect ISBN number!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;ISBN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;isbn&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getISBN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`ISBN number is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ISBN&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setISBN&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;book1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1122334455667&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ISBN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;987&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getISBN&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// ISBN number is 1122334455667&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In the above example, we got the result we expected ie 123. But you might be thinking what does this line do &lt;code&gt;book1.ISBN=987&lt;/code&gt;? &lt;br&gt;
This line adds a new variable in &lt;code&gt;book1&lt;/code&gt;'s &lt;code&gt;this&lt;/code&gt; scope. &lt;br&gt;
ie&lt;br&gt;
&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E89sbMlw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylyg6gcerqw334qckvjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E89sbMlw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylyg6gcerqw334qckvjq.png" alt="Image description" width="365" height="112"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The above pattern is good for creating private members, but it comes with a cost, which is memory. ie Every time we instantiate a new object of this &lt;code&gt;Book&lt;/code&gt; class, we create fresh new copies of &lt;code&gt;ISBN&lt;/code&gt; and &lt;code&gt;checkISBN&lt;/code&gt; bundled inside the closure of &lt;code&gt;Book&lt;/code&gt;. Hence there is wastage of memory. Therefore we should only make private attributes and methods when they are actually needed. &lt;/p&gt;




&lt;p&gt;Now let's come to the second part of the article: private static members.&lt;/p&gt;

&lt;p&gt;In the above example we used a private method &lt;code&gt;checkISBN(x)&lt;/code&gt;, you will notice that this method has nothing to do with individual objects. Only thing it does is to check the input &lt;code&gt;x&lt;/code&gt; and determine whether it is correct of not, thus there is no sense in making its seperate copy whenever a new object is instantiated. &lt;br&gt;
And therefore we need the concept of private static members.&lt;/p&gt;

&lt;p&gt;A static member is a member which belongs to the class, not the objects. ie There is only a single copy of member which is created when the class is defined. No matter how much objects are instantiated, there will only on copy of the member residing in the memory. &lt;/p&gt;

&lt;p&gt;Before creating a private static member, lets create a public static member of the class, which is very easy.&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;Book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isbn&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

  &lt;span class="nx"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getLibrary&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

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

&lt;span class="nx"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getLibrary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This book belongs to Oxford library.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;book1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// This book belongs to Oxford library.&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;To add a public static member we have to simply add the member in class's namespace. &lt;/p&gt;

&lt;p&gt;Now, lets make a private static member, which is quite tricky. &lt;/p&gt;

&lt;p&gt;Suppose we have to design a &lt;code&gt;Book&lt;/code&gt; class, which will have a private static attribute called &lt;code&gt;booksCreated&lt;/code&gt; which is initally set to zero and whenever a new book is instantiated, this variable must increment by one. We must ensure that it is kept private because we don't want it to be manipulated from outside of the class.&lt;/p&gt;

&lt;p&gt;Here we will use closures along with IIFE (Immediately Invoked Function Expression).&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;Book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&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;booksCreated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="c1"&gt;// private static attribute &lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;booksCreated&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; 
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getNumberOfBooks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;function&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;booksCreated&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;b1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Book&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;b2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Book&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;b3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getNumberOfBooks&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getNumberOfBooks&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>adventofcode</category>
    </item>
    <item>
      <title>Access your localhost from anywhere with NGROK!</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Tue, 04 Jul 2023 06:43:27 +0000</pubDate>
      <link>https://dev.to/merudra754/access-your-localhost-from-anywhere-with-ngrok-5goa</link>
      <guid>https://dev.to/merudra754/access-your-localhost-from-anywhere-with-ngrok-5goa</guid>
      <description>&lt;p&gt;When you make apps be it Nodejs or React, you use localhost server to see your development progress in realtime. &lt;/p&gt;

&lt;p&gt;Now suppose you have a remote team (or a friend) with which you want to share your progress in realtime. How would you do? &lt;/p&gt;

&lt;p&gt;You will probably use Google Meet or any screen sharing service to show your work. But this is not efficient because they can't access your localhost because it is not publicly available.  &lt;/p&gt;

&lt;p&gt;And if you are thinking that you will host the app on a web hosting service, make it live and then share the public url, then my friend it is very inefficient and time consuming. &lt;/p&gt;

&lt;p&gt;In this article, I will share a wonderful tool you can use to achieve this purpose.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;NGROK&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;NGROK is a tool used to tunnel your localhost to a live url.&lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Go to ngrok.com and signup. After registering you will get a auth token.&lt;/li&gt;
&lt;li&gt;Download the zip file for your respective OS.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Unzip the file and run the executable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x7A3qPqV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aoq1hqhons1rylmjheyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x7A3qPqV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aoq1hqhons1rylmjheyg.png" alt="Image description" width="72" height="89"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type the following command (replace token with yours)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lDInT0HN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avdfmg7wurr1uficrd67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lDInT0HN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avdfmg7wurr1uficrd67.png" alt="Image description" width="694" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To start a HTTP tunnel forwarding to your local port 80, run this next (replace the port number with the port of your localhost on which your app is listening):&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--18QVSmOU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1irzsu08ckq23hjdt7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--18QVSmOU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1irzsu08ckq23hjdt7k.png" alt="Image description" width="164" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You will get a url which can be opened from anywhere and the url will show the web page served by your localhost server.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>http requests are always served at port 80. PROOF!</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Mon, 03 Jul 2023 18:57:14 +0000</pubDate>
      <link>https://dev.to/merudra754/http-requests-always-goes-to-port-80-proof-10e7</link>
      <guid>https://dev.to/merudra754/http-requests-always-goes-to-port-80-proof-10e7</guid>
      <description>&lt;p&gt;We know that http requests are by default goes to port 80. &lt;br&gt;
In this article I will prove that this fact is true. &lt;/p&gt;

&lt;p&gt;For this demonstration, I am going to create a tiny Nodejs 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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`listening on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the server by typing &lt;code&gt;node app.js&lt;/code&gt; in the terminal.&lt;/p&gt;

&lt;p&gt;Now go to the browser and write the url &lt;code&gt;http://localhost:5000&lt;/code&gt;.&lt;br&gt;
The output will be:&lt;br&gt;
&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y0H7OkIR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkbyv5b11hhhjga43exi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y0H7OkIR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkbyv5b11hhhjga43exi.png" alt="Image description" width="339" height="125"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now, rewrite the url again but omit the port number this time. ie &lt;br&gt;
search &lt;code&gt;http://localhost&lt;/code&gt;.&lt;br&gt;
Now you will get error this time:&lt;br&gt;
&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d0mjSCCD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/295jyr2mxz32y08rpe0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d0mjSCCD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/295jyr2mxz32y08rpe0n.png" alt="Image description" width="679" height="585"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You get this error because you made a http request and http requests are resolved on port 80, but your Nodejs server is listening on port 5000 and there is no service running on port 80. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now the magic is going to happen.&lt;/strong&gt;&lt;br&gt;
If you want to &lt;code&gt;http://localhost&lt;/code&gt; doesn't throw error on the browser, you have to make some changes in the Nodejs 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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`listening on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Restart the server and search &lt;code&gt;http://localhost&lt;/code&gt; in the browser.&lt;br&gt;
The output is:&lt;br&gt;
&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KDtz6XKj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c20nblgfdachflxo6pb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KDtz6XKj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c20nblgfdachflxo6pb5.png" alt="Image description" width="259" height="121"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HOLLA&lt;/strong&gt;! There is no error! And we did wrote the port number in the url.&lt;/p&gt;

&lt;p&gt;Thus it is proved that http request are resolved on port 80.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>networking</category>
    </item>
    <item>
      <title>What is NGINX and how reverse proxies work?</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Mon, 03 Jul 2023 18:33:49 +0000</pubDate>
      <link>https://dev.to/merudra754/what-is-nginx-and-how-reverse-proxies-work-173l</link>
      <guid>https://dev.to/merudra754/what-is-nginx-and-how-reverse-proxies-work-173l</guid>
      <description>&lt;p&gt;Every domain name resolves to a unique IP address. &lt;br&gt;
For example: &lt;code&gt;www.gooogle.com&lt;/code&gt; is mapped to &lt;code&gt;142.250.191.78&lt;/code&gt; ipv4. &lt;/p&gt;

&lt;p&gt;Whenever you host your program (for example: nodejs server or php server) on a remote machine (for example: AWS EC2 instances or Digitalocean), you are given a reserved public IP address with which you can connect with that remote device through SSH Terminal or any SSH client like PuTTY.&lt;/p&gt;

&lt;p&gt;Now, suppose you visit &lt;code&gt;www.google.com/maps&lt;/code&gt;. When you hit enter, your request is sent to the unqiue server which has the IP address &lt;code&gt;142.250.191.78&lt;/code&gt;. Now your request has reached to the correct device, but how does &lt;code&gt;/maps&lt;/code&gt; goes to the correct program running inside that device? Suppose you want that every &lt;code&gt;www.google.com/maps&lt;/code&gt; must be served by a Nodejs server running inside that EC2 instance and &lt;code&gt;www.google.com/docs&lt;/code&gt; must be served by a PHP server. How can we forward the &lt;code&gt;/maps&lt;/code&gt; request to Nodejs server and &lt;code&gt;/docs&lt;/code&gt; request to PHP server?&lt;/p&gt;

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

&lt;p&gt;In the above diagram it is clearly shown that multiple requests are resolved by different app servers inside our machine. &lt;br&gt;
For example: &lt;code&gt;/maps&lt;/code&gt; can be served by a Nodejs server, &lt;code&gt;/docs&lt;/code&gt; can be served by a PHP server etc. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
This is done by NGINX server which is installed on the physical machine. &lt;/p&gt;

&lt;p&gt;NGINX maps the incoming request to be resolved by some other backend server. This process is called reverse proxy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An other popoular proxy server is HAproxy.&lt;/p&gt;

&lt;p&gt;Now I am diving deep into the topic, so be attentive.&lt;br&gt;
First of all let me make a quote.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By default, all HTTP requests are served on port 80. &lt;br&gt;
By default, all HTTPS requests are served on port 443.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let suppose your &lt;code&gt;/maps&lt;/code&gt; request is to be served by a Node server listening on port 1234 and your &lt;code&gt;/docs&lt;/code&gt; request is to be servered by a PHP server on port 1235.&lt;/p&gt;

&lt;p&gt;Now any request coming from client in the form of &lt;code&gt;/maps&lt;/code&gt; or &lt;code&gt;/docs&lt;/code&gt;, carries a default port 80 if it is an http request and 443 if it is an https request.&lt;/p&gt;

&lt;p&gt;So, we must map the incoming request to different ports, which is done by NGINX.&lt;/p&gt;

&lt;p&gt;Following image illustrates the process:&lt;/p&gt;

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

&lt;p&gt;NGINX is written in C and it is very performant. It can handle ~10000 concurrent requests!&lt;br&gt;
It can do multiple things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load balancing&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Http caching&lt;/li&gt;
&lt;li&gt;Reverse proxy&lt;/li&gt;
&lt;li&gt;Websocket connection&lt;/li&gt;
&lt;li&gt;Handling of static files, index files, and auto-indexing.&lt;/li&gt;
&lt;li&gt;URL redirection and rewriting...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following image illustrates the load balancing part:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aTDgaWwZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n78twxs5y6ww47g6aj3z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aTDgaWwZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n78twxs5y6ww47g6aj3z.png" alt="Image description" width="647" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks, please upvote.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>networking</category>
    </item>
    <item>
      <title>Deep dissection of const declarations</title>
      <dc:creator>Rudra Pratap</dc:creator>
      <pubDate>Thu, 08 Jun 2023 15:38:10 +0000</pubDate>
      <link>https://dev.to/merudra754/misconception-regarding-const-35mo</link>
      <guid>https://dev.to/merudra754/misconception-regarding-const-35mo</guid>
      <description>&lt;p&gt;In this post, I will be describing why we should be vigilant while using const to declare variables. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;const variables are mutable.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;countries&lt;/span&gt; &lt;span class="o"&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;India&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;USA&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;UK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;countries&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="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Japan&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countries&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

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

&lt;/div&gt;



&lt;p&gt;What do you anticipate from above code? Will it throw error?&lt;/p&gt;

&lt;p&gt;Well no, the output is :&lt;br&gt;
&lt;code&gt;[ 'India', 'Japan', 'UK' ]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can clearly see that &lt;code&gt;countries&lt;/code&gt; variable is altered without causing any exception. This shows that &lt;code&gt;const&lt;/code&gt; can't make variables immutable.&lt;/p&gt;

&lt;p&gt;In the same sequence, try to guess the output of the following code:&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;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rudra&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;myName&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="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;R&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Did you guess the output to be &lt;code&gt;Rudra&lt;/code&gt;? &lt;br&gt;
If yes, then unfortunately your Javascript basics are not strong.&lt;br&gt;
The output will be &lt;code&gt;rudra&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here is the reason: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In Javascript, all the primitives ( Numbers, Strings, Boolean, BigInt, Symbol, Undefined and Null) are immutable, ie once they are initialised, their value can't be changed, but can only be reassigned. All primitives are stored in call stack.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Whereas, all the reference variables ( Objects, Arrays, Maps, Sets ) are mutable, ie there value can be changed directly from the memory location where they are stored. All references are stored in heap area.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;const variables can't be reassigned.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the sole purpose of using &lt;code&gt;const&lt;/code&gt;. Once a variable declared using &lt;code&gt;const&lt;/code&gt;, can't be reassigned with other value.&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;countries&lt;/span&gt; &lt;span class="o"&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;India&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;USA&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;UK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;countries&lt;/span&gt; &lt;span class="o"&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;India&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;USA&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;UK&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countries&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Output: &lt;br&gt;
&lt;code&gt;TypeError: Assignment to constant variable.&lt;/code&gt;&lt;/p&gt;

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