<?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: Amr Elmohamady</title>
    <description>The latest articles on DEV Community by Amr Elmohamady (@amrelmohamady).</description>
    <link>https://dev.to/amrelmohamady</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%2F517839%2F3cbf0a6d-1c0f-465f-8338-bed2a9e39e3d.jpg</url>
      <title>DEV Community: Amr Elmohamady</title>
      <link>https://dev.to/amrelmohamady</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amrelmohamady"/>
    <language>en</language>
    <item>
      <title>I built a dev.to stats card generator (followers &amp; views count)</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Tue, 25 Oct 2022 15:59:08 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/i-built-a-devto-stats-card-generator-followers-views-count-2b6b</link>
      <guid>https://dev.to/amrelmohamady/i-built-a-devto-stats-card-generator-followers-views-count-2b6b</guid>
      <description>&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;I like to share my achievements and having more than 30k views (at the time of writing) on my dev.to blog is a good achievement. Also, I want you to know that my content is helpful and trustworthy, because if it is not then why other people follow me and read my articles!&lt;/p&gt;

&lt;p&gt;Dev.to doesn't display followers count or views count so I built a Node.js server that scrapes my followers and views count and renders an SVG image card to display them in a cool way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Amr2812/devto-stats-card#readme" rel="noopener noreferrer"&gt;Here's an example embed in the GitHub repository.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to see it get updated &lt;a href="https://dev.to/amrelmohamady"&gt;follow me or view one of my articles&lt;/a&gt; then simply refresh.&lt;/p&gt;

&lt;h2&gt;
  
  
  How
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The Node.js server accepts an HTTP request&lt;/li&gt;
&lt;li&gt;It fetches my dashboard using Axios (HTTP Client)&lt;/li&gt;
&lt;li&gt;It gets the views and followers count using cheerio (HTML Parser)&lt;/li&gt;
&lt;li&gt;It puts the values in an already designed SVG template (by draw.io)&lt;/li&gt;
&lt;li&gt;Sends the generated SVG back to the client to display the SVG image&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I used SVG because the It is actually some XML code describing how it looks so I can easily embed my values in the text tags without doing heavy image processing.&lt;/p&gt;

&lt;p&gt;When I fetch my dashboard I use an authentication cookie which I got from the console and It will be expired next year if I didn't visit dev.to or no one visited a website that displays my stats card so, no need to automate a login workflow.&lt;/p&gt;

&lt;p&gt;It is open source so you can fork the repo and deploy your own server from &lt;a href="https://github.com/Amr2812/devto-stats-card" rel="noopener noreferrer"&gt;https://github.com/Amr2812/devto-stats-card&lt;/a&gt;.&lt;br&gt;
You will need to rename &lt;code&gt;.env.sample&lt;/code&gt; file to &lt;code&gt;.env&lt;/code&gt; and replace the cookie header constant to your own one and in the &lt;code&gt;config.js&lt;/code&gt; file you will need to replace the blog URL constant to your own one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Star the project If you like it ⭐&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;If you like the article you can join my &lt;a href="https://amrelmohamady.hashnode.dev/newsletter" rel="noopener noreferrer"&gt;newsletter&lt;/a&gt; and follow me.&lt;/p&gt;

&lt;p&gt;You can also buy me a coffee that would help me grow as an open source developer :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/amrelmohamady" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>node</category>
      <category>javascript</category>
      <category>community</category>
    </item>
    <item>
      <title>Three ways to scale your Database (Replication vs Sharding vs Partitioning)</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Thu, 20 Oct 2022 11:57:38 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/three-ways-to-scale-your-database-replication-vs-sharding-vs-partitioning-1en7</link>
      <guid>https://dev.to/amrelmohamady/three-ways-to-scale-your-database-replication-vs-sharding-vs-partitioning-1en7</guid>
      <description>&lt;p&gt;Taking your database to the next level regarding scale is often harder than scaling web servers. In web servers, you can start new instances of your app and do horizontal scaling or you can increase server resources (memory/cpu) and do vertical scaling. But, when it comes to the database side your queries will get slower and you might run out of space.&lt;/p&gt;

&lt;p&gt;In this article, I will introduce three ways to scale your database:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Replication&lt;/li&gt;
&lt;li&gt;Sharding&lt;/li&gt;
&lt;li&gt;Partitioning&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Replication
&lt;/h3&gt;

&lt;p&gt;Replicating the database is to create copies of same data for more than one server.&lt;br&gt;
With multiple copies of data on different database servers, replication provides a level of fault tolerance against the loss of a single database server.&lt;/p&gt;

&lt;h4&gt;
  
  
  The main advantages of replication are:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancing&lt;/strong&gt;: Queries will be distributed across multiple servers (maybe in different data centers in different regions)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High availability&lt;/strong&gt;: If one server is down there are other servers to handle queries&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  There are different types of replication:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single-leader architecture&lt;/strong&gt;: One server accepts writes from clients, and replicas get data from there. This is the easiest method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-leader architecture&lt;/strong&gt;: Multiple servers that accept writes and each replica set get data from their leader. It's used in different data centers so writes from different regions become faster like read queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No-leader architecture&lt;/strong&gt;: All servers accepts writes and reads. All replicas get data from each other. This architecture is supported by databases like Cassandra to achieve maximum scalability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sharding
&lt;/h3&gt;

&lt;p&gt;Sharding is a method for &lt;strong&gt;distributing&lt;/strong&gt; data across multiple machines. Running queries on a single server with a lot of data will consume a lot of CPU but running queries on a subset of this data will be much faster and will consume less CPU.&lt;br&gt;
Sharding can be used with replication in which each shard will be replicated.&lt;br&gt;
Sharding is complex and require some experience because you will need to analyze queries and data structure to determine the sharding key and algorithm.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Sharding key&lt;/strong&gt;: a specific column value that indicates which shard this row is stored in.&lt;br&gt;
&lt;strong&gt;Sharding algorithm&lt;/strong&gt;: an algorithm to distribute your data to one or more shards.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  The main advantages of sharding are:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster Queries&lt;/strong&gt;: less data -&amp;gt; less CPU/memory usage -&amp;gt; faster queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage Capacity&lt;/strong&gt;: Servers will not run out of space because data is distributed across multiple servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Availability&lt;/strong&gt;: If one shard is down other data won't be lost.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Sharding may not be a good option if most of your queries are JOINs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Partitioning
&lt;/h3&gt;

&lt;p&gt;Partitioning is dividing large tables into multiple tables. By dividing a large table into smaller, individual tables, queries that access only a fraction of the data can run faster and use less CPU because there is less data to scan.&lt;br&gt;
Unlike Sharding and Replication, Partitioning is vertical scaling because each data partition is in the same server.&lt;br&gt;
Partitioning should be done when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have large tables, like in a &lt;code&gt;users&lt;/code&gt; table, you can partition based on country.&lt;/li&gt;
&lt;li&gt;You have historical data that are rarely queried and example would be having tables like &lt;code&gt;jobs_2020&lt;/code&gt; and &lt;code&gt;jobs_2021&lt;/code&gt; for old jobs but for new ones there is the table &lt;code&gt;jobs&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The main advantage of partitioning is:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster Queries&lt;/strong&gt;: smaller tables and indexes -&amp;gt; less data to scan -&amp;gt; less CPU/memory usage -&amp;gt; faster queries.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you liked the article you can join my &lt;a href="https://amrelmohamady.hashnode.dev/newsletter"&gt;newsletter&lt;/a&gt; and follow me.&lt;/p&gt;

</description>
      <category>database</category>
      <category>architecture</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>How I moved to hashnode?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Sat, 18 Jun 2022 06:16:53 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/how-i-moved-to-hashnode-2dcc</link>
      <guid>https://dev.to/amrelmohamady/how-i-moved-to-hashnode-2dcc</guid>
      <description>&lt;p&gt;I moved my blog from dev.to to hashnode.&lt;/p&gt;

&lt;p&gt;Hashnode has amazing feature that blew my mind like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I own my content and all traffic goes to me.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I can add my own domain later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I can have static pages like about, projects, etc.. so it's like a portfolio and blog all in one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Free In-built newsletter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom page rules for creating customized URLs or redirects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I can enable listen to audio feature.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I can show views count on my articles.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, I transferred my articles from there using the hashnode dev.to importer and updated my articles on dev.to to have a canonical url to refer to my hashnode articles so my hashnode articles can be ranked higher in search engines.&lt;/p&gt;

&lt;p&gt;Now if I want to cross post to dev.to I can use the &lt;a href="https://dev.to/settings/extensions"&gt;RSS feed importer from dev.to&lt;/a&gt; and mark my hashnode to be the canonical url.&lt;/p&gt;

&lt;p&gt;So, you can subscribe to my newsletter in my hasnode blog here:&lt;br&gt;
&lt;a href="https://amrelmohamady.hashnode.dev/"&gt;amrelmohamady.hashnode.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>showdev</category>
      <category>portfolio</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why and how to use the the Node.js Event Emitter in real projects?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Thu, 14 Apr 2022 07:21:08 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/why-and-how-to-use-the-the-nodejs-event-emitter-in-real-projects-32kd</link>
      <guid>https://dev.to/amrelmohamady/why-and-how-to-use-the-the-nodejs-event-emitter-in-real-projects-32kd</guid>
      <description>&lt;h2&gt;
  
  
  The Observer pattern and the Event Emitter
&lt;/h2&gt;

&lt;p&gt;The Observer pattern defines an object (called the subject) that can notify a set of observers (or listeners) when a change in its state occurs.&lt;/p&gt;

&lt;p&gt;It can be implemented in OOP by using a class that can register and store listeners in an array and calls them when something happens.&lt;/p&gt;

&lt;p&gt;In Node.js it can be implemented using the EventEmitter class which is imported from the &lt;code&gt;events&lt;/code&gt; built-in module. It allows to emit and listen for events (with multiple listeners).&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%2Fxijz5rcord66s2fnbjtr.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%2Fxijz5rcord66s2fnbjtr.png" alt="EventEmitter Illustration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The EventEmitter is exported from the events core module:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;events&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The essential methods of the EventEmitter are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;on(event, listener)&lt;/code&gt;: This method allows us to register a new listener (a function) for the given event type (a string).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;once(event, listener)&lt;/code&gt;: This method registers a new listener, which is then removed after the event is emitted for the first time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;emit(event, [arg1], [...])&lt;/code&gt;: This method produces a new event and provides additional arguments to be passed to the listeners.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;removeListener(event, listener)&lt;/code&gt;: This method removes a listener for the specified event type.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When to use the EventEmitter
&lt;/h2&gt;

&lt;p&gt;It can be used in backend projects and here's a real example where I used it, In an LMS, when a teacher publishes a new lesson I need to send emails and notifications to all the students that are subscribed to the teacher, so we shouldn't put that code in the publish lesson request so the teacher doesn't wait for the emails and notifications to be sent to get a success response and we separate the publish lesson logic from the emails and notifications part to have clean code by achieving the separation of concerns principle.&lt;br&gt;
Another example is when you need to update a real-time dashboard or to send a notification to your investors when new users signup.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use the EventEmitter in real projects
&lt;/h2&gt;

&lt;p&gt;Create this folder structure:&lt;/p&gt;

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

/events
    /subscribers
        /lessons.subscriber.js
        /users.subscriber.js
    /emitter.js
    /index.js


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;In &lt;code&gt;/emitter.js&lt;/code&gt;:&lt;/strong&gt;&lt;br&gt;
Create a new EventEmitter and export it.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;events&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;In &lt;code&gt;/index.js&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
Import the created EventEmitter and export it with the events' names.&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;EventEmitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./emitter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;events&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;LESSON_PUBLISHED&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;LESSON_PUBLISHED&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;NEW_SIGNUP&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NEW_SIGNUP&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;we can also separate the events' names in a different file but there's no need to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In &lt;code&gt;subscribers/users.subscriber.js&lt;/code&gt;:&lt;/strong&gt;&lt;br&gt;
Import the events and the EventEmitter instance and listen to the events.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;events&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEW_SIGNUP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now we are done with the listeners part, in your controller or service you can import the EventEmitter instance and the events' names then emit the event and pass the data you want like:&lt;/p&gt;

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

&lt;span class="nx"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEW_SIGNUP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;




&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you like this article, you can follow the blog if you want more.&lt;br&gt;
&lt;a href="[https://www.linkedin.com/in/amr-elmohamady](https://www.linkedin.com/in/amr-elmohamady)"&gt;My LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>How to insert random data for testing in PostgreSQL?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Wed, 06 Apr 2022 21:14:52 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/how-to-insert-random-data-for-testing-in-postgresql-2l98</link>
      <guid>https://dev.to/amrelmohamady/how-to-insert-random-data-for-testing-in-postgresql-2l98</guid>
      <description>&lt;p&gt;Sometimes you need to have hundreds of thousands or even millions of rows to test the performance of your database and queries because we can't explore performance if we only have 10 rows, so before playing with performance we need to make some test data.&lt;/p&gt;

&lt;p&gt;But can't we just use a shell script or a (your favorite language) script, yes you can but try generating 1M rows with your script then save to the database but your script memory will not be able to take 1M rows in memory so you will have to create a stream or generate chunks of data then save to the database or a CSV file then import it to the database, but why all that while you have amazing functions from PostgreSQL to help you.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;repeat()&lt;/code&gt; Function
&lt;/h3&gt;

&lt;p&gt;A function that takes two parameters &lt;code&gt;repeat(string to repeat, number of times to repeat)&lt;/code&gt; to repeat a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stringColumn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Wow "&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will insert a row with a stringColumn with a value of &lt;code&gt;Wow Wow Wow&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;generate_series()&lt;/code&gt; Function
&lt;/h3&gt;

&lt;p&gt;A function that takes two required parameters and an optional one &lt;code&gt;generate_series(start, stop, increment by [default is 1])&lt;/code&gt; to generate a series of numbers each in a row.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;generate_series&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;1000&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will insert 1000 rows each with an id equal to the previous id incremented by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;random()&lt;/code&gt; Function
&lt;/h3&gt;

&lt;p&gt;A function that generates a random float from 0 to 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate an id of three digits from 0 to 100 (trunc to make the float an integer).&lt;/p&gt;

&lt;h3&gt;
  
  
  ALL TOGETHER:
&lt;/h3&gt;

&lt;p&gt;Let's create a players table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;players&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;about&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then let's insert 1000 rows with some random data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;players&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;about&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;generate_series&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;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;  &lt;span class="n"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'A cool player. '&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="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;'My number is '&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you like this article, you can follow my LinkedIn at:&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/amr-elmohamady"&gt;https://www.linkedin.com/in/amr-elmohamady&lt;/a&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>sql</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to deploy Node.js Socket.IO server with load balancing &amp; reverse proxy using pm2 &amp; Nginx?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Mon, 06 Sep 2021 22:05:00 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/how-to-deploy-node-js-socket-io-server-with-load-balancing-reverse-proxy-using-pm2-nginx-7k0</link>
      <guid>https://dev.to/amrelmohamady/how-to-deploy-node-js-socket-io-server-with-load-balancing-reverse-proxy-using-pm2-nginx-7k0</guid>
      <description>&lt;h2&gt;
  
  
  Imagine that you are building an app with chat rooms and it will have thousands of users how do you think a server could handle this load ?!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  With Two concepts:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Reverse Proxy&lt;/strong&gt;&lt;br&gt;
A reverse proxy server provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.&lt;/p&gt;

&lt;p&gt;Examples of Web Servers are Nginx and Apache.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Load Balancing&lt;/strong&gt;&lt;br&gt;
A reverse proxy server can act as a “traffic cop,” sitting in front of your backend servers and distributing client requests across a group of servers in a manner that maximizes speed and capacity utilization while ensuring no one server is overloaded, which can degrade performance. If a server goes down, the load balancer redirects traffic to the remaining online servers.&lt;/p&gt;



&lt;p&gt;Node.js is single threaded and it runs on a single core by default, so it has a &lt;a href="https://nodejs.org/docs/latest-v17.x/api/cluster.html" rel="noopener noreferrer"&gt;native cluster module&lt;/a&gt; to run multiple instances on all the CPU cores and load balance the requests on the instances.&lt;/p&gt;

&lt;p&gt;We have two options either use the cluster module in the application code or use a process manager like &lt;a href="https://pm2.keymetrics.io/" rel="noopener noreferrer"&gt;Pm2&lt;/a&gt;.&lt;br&gt;
Pm2 is more suitable for production.&lt;/p&gt;

&lt;p&gt;First, we'll install the pm2 package globally:&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;npm i pm2 -g&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We'll run the app in the &lt;a href="https://pm2.keymetrics.io/docs/usage/cluster-mode/" rel="noopener noreferrer"&gt;cluster mode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So set the start command to be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm2 start index.js -i max
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-i&lt;/code&gt; for number of instances and &lt;code&gt;max&lt;/code&gt; to be scaled across all CPUs available&lt;/p&gt;

&lt;p&gt;To stop the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm2 stop index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Inspect Logs:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To restart the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm2 restart index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we have our app scaled on one server, we need to have the app deployed on multiple machines as horizontal scaling. NGINX is responsible for load balancing requests on multiple servers as a reverse proxy.&lt;/p&gt;

&lt;p&gt;In nginx main config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;http&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kn"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;# 80 for http, 443 for https&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;api.example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;X-Forwarded-For&lt;/span&gt; &lt;span class="nv"&gt;$proxy_add_x_forwarded_for&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;Host&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="kn"&gt;proxy_pass&lt;/span&gt; &lt;span class="s"&gt;http://nodes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="kn"&gt;proxy_http_version&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;Upgrade&lt;/span&gt; &lt;span class="nv"&gt;$http_upgrade&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;Connection&lt;/span&gt; &lt;span class="s"&gt;"upgrade"&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="kn"&gt;upstream&lt;/span&gt; &lt;span class="s"&gt;nodes&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;server&lt;/span&gt; &lt;span class="s"&gt;server1.example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server&lt;/span&gt; &lt;span class="s"&gt;server2.example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server&lt;/span&gt; &lt;span class="s"&gt;server3.example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, let's understand this file line by line:&lt;/p&gt;

&lt;p&gt;First, In the server config we listen to the default port of http which is 80, 443 for https.&lt;/p&gt;

&lt;p&gt;Then, the server name = site's domain name&lt;/p&gt;

&lt;p&gt;Then, at the root location we set couple of headers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The X-Forwarded-For (XFF) header is a de-facto standard header for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or a load balancer. When traffic is intercepted between clients and servers, server access logs contain the IP address of the proxy or load balancer only. To see the original IP address of the client, the X-Forwarded-For request header is used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Host header to determine which server the request should be routed to.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;we'll pass proxy_pass for now&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;http version to be 1.1 the version that supports WebSockets&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HTTP Upgrade is used to indicate a preference or requirement to switch to a different version of HTTP or to another protocol, if possible, so here in socket.IO implementation we need to upgrade to a websocket connection&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don't know how Socket.IO work under the hood I suggest you read &lt;a href="https://socket.io/docs/v4/how-it-works/" rel="noopener noreferrer"&gt;this page&lt;/a&gt; from the Socket.IO Documentation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upstream nodes block is used to set the servers that our load balancer will use, so we set proxy_pass in the location block to be the upstream "nodes" so it can do its reverse proxy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, our load balancer will redirect calls to our servers and each server will redirect calls to on of its cluster instances. That is fine unless when USER_A connects to SERVER_1 then joins a room called GROUP_A and sends a message, the message will be broadcasted to all users in GROUP_A on SERVER_1 but what about other users on SERVER_2 that are in GROUP_A?&lt;br&gt;
To solve this we need servers to communicate and in our case we need to use a Pub/Sub message broker so when USER_A connects to SERVER_1 the sends a message on GROUP_A, SERVER_1 will publish an event to all servers telling them to broadcast this message for all users in GROUP_A.&lt;/p&gt;

&lt;p&gt;Socket.IO supports multiple adapters and the most recommended one is &lt;a href="https://socket.io/docs/v4/redis-adapter/" rel="noopener noreferrer"&gt;Redis adapter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1659025781010%2FSuueOeDSZ.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%2Fv1659025781010%2FSuueOeDSZ.png" alt="socket.io.png"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I hope you found this article useful and please share your thoughts below :-)&lt;/p&gt;

&lt;p&gt;You can also buy me a coffee that would help :)&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/amrelmohamady" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/amr-elmohamady" rel="noopener noreferrer"&gt;Amr Elmohamady&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>node</category>
      <category>webdev</category>
      <category>nginx</category>
      <category>devops</category>
    </item>
    <item>
      <title>Why Frontend Developers Should Learn Node.js and Express?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Wed, 17 Mar 2021 22:26:19 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/why-frontend-developers-should-learn-node-js-and-express-1n5m</link>
      <guid>https://dev.to/amrelmohamady/why-frontend-developers-should-learn-node-js-and-express-1n5m</guid>
      <description>&lt;p&gt;When I was using Vue (doesn't matter which framework) for Frontend I didn't understand this weird folder structure, I didn't understand how these files are served and how they are built and when I started learning Nuxt which is for Vue Server-Side Rendering, It was weirder for me like how SSR Works, how routes are being generated automatically and how middleware works and this when I decided to learn Node and the reason why I picked node wasn't to understand frontend stuff but to be a Full-stack developer and I was confused what to choose PHP and Laravel or Node and Express and thanks god I chose Node not because Node is better than PHP or this stuff but because I was so Lazy to learn a new language (PHP) and I didn't know that I am so lucky.&lt;/p&gt;

&lt;p&gt;Now, I know how NPM Scripts, task runners, and building tools work and I know how to solve problems or bugs that I face in the Frontend part easily or at least much easier than before.&lt;/p&gt;

&lt;p&gt;Something else if you are only a Frontend developer learning Node and Express will give you some knowledge about how the backend works and don't worry they are not hard to learn.&lt;/p&gt;

&lt;p&gt;Also, Cloud Functions (serverless) will be easy for you when you learn node, and don't tell me why cloud functions are Important for Frontend Developers as every single Frontend developer I know knows about cloud functions.&lt;/p&gt;

&lt;p&gt;Even if you don't want to be a Full-stack developer or you are but you don't know Node.js then I think you should learn Node and Express or even take some crash courses for the reasons I wrote above.&lt;/p&gt;




&lt;p&gt;I hope you enjoyed this tiny article and this is article is about my thoughts and should doesn't mean must :-)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also buy me a coffee that would help :)&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/amrelmohamady" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>node</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Cloudinary VS Firebase Cloud Storage: Pros and Cons</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Mon, 22 Feb 2021 11:19:29 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/cloudinary-vs-firebase-cloud-storage-pros-and-cons-2ljl</link>
      <guid>https://dev.to/amrelmohamady/cloudinary-vs-firebase-cloud-storage-pros-and-cons-2ljl</guid>
      <description>&lt;p&gt;This article will help you to choose your cloud storage provider for your next project or your blog or an event, based on free pricing plans.&lt;/p&gt;

&lt;p&gt;The moment you realize that you need to choose a cloud storage provider to use in your project and there are multiple options to choose from and you start searching for storage providers and you find a lot of choices and you want to find something that has a good free plan to start with then you might find Cloudinary and Firebase Cloud Storage.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://cloudinary.com/"&gt;Cloudinary&lt;/a&gt;: pros and cons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;More Storage as you get 25 Monthly Credits: 25k transformations or&lt;br&gt;
25 GB of managed storage or&lt;br&gt;
25 GB of net viewing bandwidth&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Image and video transformations (e.g.:change the size of your assets)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Video transcoding and adaptive streaming&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better Admin Dashboard (OS-like)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Smaller Community&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is minimum file size&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Has some limitations if you are using it from a javascript frontend like the inability of deleting images.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://cloud.google.com/storage/"&gt;Firebase Storage&lt;/a&gt;: pros and cons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Wide Community&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No minimum file size&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better to use if you have experience with other Firebase services like Firestore or Authentication&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;5GB Stored&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Finally, I hope you enjoyed this article, and if you have other opinions please feel free to comment below or contact me.&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://twitter.com/Amr__Elmohamady"&gt;@Amr__Elmohamady&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>cloud</category>
      <category>serverless</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to create a custom global Nuxt plugin (toast)?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Sat, 13 Feb 2021 21:28:15 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/how-to-create-a-custom-global-nuxt-plugin-toast-1976</link>
      <guid>https://dev.to/amrelmohamady/how-to-create-a-custom-global-nuxt-plugin-toast-1976</guid>
      <description>&lt;p&gt;In this article, we'll be building a dynamic global nuxt plugin that is going to be a Toast (snackbar).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vue&lt;/li&gt;
&lt;li&gt;Vuex&lt;/li&gt;
&lt;li&gt;Nuxt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So&lt;/strong&gt;, Let's start by creating a Nuxt app using npx:&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="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;nuxt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;nuxt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;toast&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go with the steps and in the UI framework option choose Vuetify.js as we're going to be using it in this tutorial but, if you don't want to use Vuetify you can change the UI framework you like or even without a UI framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt; a file named &lt;code&gt;snackbar.js&lt;/code&gt; in the store folder to use Vuex then write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We export the state function that has content and color values for the toast and the mutations object that contains the show message function that sets the state values to the payload values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, Create a file named &lt;code&gt;notifier.js&lt;/code&gt; in the plugins folder and write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default &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="nx"&gt;store&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;inject&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="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;notifier&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="o"&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;color&lt;/span&gt; &lt;span class="o"&gt;=&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="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;snackbar/showMessage&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="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, we are exporting the plugin's function that we're passing two parameters which are app and store object because we will use vuex store to set the payload that sets the state values to our desired content and color then, there's the second parameter inject that will inject our notifier function to become a global nuxt function to be called like &lt;code&gt;this.$notifier&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, create a file named &lt;code&gt;Snackbar.vue&lt;/code&gt; in the components folder and write the vue template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;v-snackbar&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"show"&lt;/span&gt; &lt;span class="na"&gt;:color=&lt;/span&gt;&lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;v-slot:action=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ attrs }"&amp;gt;
      &lt;span class="nt"&gt;&amp;lt;v-btn&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"white"&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt; &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"attrs"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"show = false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Close
      &lt;span class="nt"&gt;&amp;lt;/v-btn&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/v-snackbar&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you see we used vuetify's snackbar component for our toast as I said if you don't want to use vuetify create your custom component as you want.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, write below the template the script tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nf"&gt;created&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;$store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;mutation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mutation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;snackbar/showMessage&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;snackbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&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;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;snackbar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&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;show&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, we're defining the data(showSnackbar, message, color), In the &lt;code&gt;created()&lt;/code&gt; hook we use the &lt;code&gt;this.$store.subscribe&lt;/code&gt; function to subscribe to store mutations as we get mutation and state params so we check if the mutation type is equal to "snackbar/showMessage" (snackbar.js file and showMessage function at our store).&lt;/p&gt;

&lt;p&gt;(&lt;a href="https://vuex.vuejs.org/api/#subscribe" rel="noopener noreferrer"&gt;for more info about store subscribe&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, we import our snackbar component to the &lt;code&gt;default.vue&lt;/code&gt; layout file like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;v-app&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-main&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;v-container&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;nuxt&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/v-container&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/v-main&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;Snackbar&amp;gt;&amp;lt;/Snackbar&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/v-app&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Snackbar&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;~/components/Snackbar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Snackbar&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt;, the last thing we do to make the plugin work is to define our plugin in the &lt;code&gt;nuxt.config.js&lt;/code&gt; file like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="err"&gt;plugins:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"~/plugins/notifier.js"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;So&lt;/strong&gt;, let's try our plugin in &lt;code&gt;index.vue&lt;/code&gt; in the &lt;code&gt;mounted()&lt;/code&gt; hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;mounted&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;$notifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YAY Our Plugin worked Successfully!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use it for HTTP request responses or however you want to use it.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed the article and found it useful!&lt;/p&gt;




&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/" rel="noopener noreferrer"&gt;&lt;strong&gt;If you like this article you can subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also buy me a coffee that would help :)&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/amrelmohamady" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>css</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What to do if you don't like CSS?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Sun, 31 Jan 2021 01:58:47 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/what-to-do-if-you-don-t-like-css-2l6h</link>
      <guid>https://dev.to/amrelmohamady/what-to-do-if-you-don-t-like-css-2l6h</guid>
      <description>&lt;h2&gt;
  
  
  Writing CSS sucks!
&lt;/h2&gt;

&lt;p&gt;It's so painful for me to write CSS code even if using a CSS Preprocessor like SASS or LESS, It makes it easier though! &lt;/p&gt;

&lt;p&gt;Writing CSS is not interesting for me and not only me there is a lot of people who hate CSS just like me or even more. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;You don't have to be a CSS hater to read this article!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I used to build projects using CSS before but when I started coding JavaScript I liked writing Logic more than styling and when I start a project I had to write CSS but I Wanted to write logic more than Styling so...&lt;/p&gt;

&lt;p&gt;So, the solution I found that I am currently using is &lt;a href="https://material.io"&gt;Google Material Design&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Google Material Design Guidelines are some design guidelines that Google uses for all of its projects so as developers how to get benefit from those Guidelines ?!&lt;/p&gt;

&lt;p&gt;We use Frameworks that are built on Material Design Guidelines.&lt;br&gt;
I mean using Component-based Frameworks.&lt;/p&gt;

&lt;p&gt;Component-based Frameworks are Frameworks with built-in components you can use without writing one line of CSS code.&lt;/p&gt;

&lt;p&gt;There is a lot of Frameworks that Component-based but they are not all good. Material Design Frameworks follow standards made by Google's Expert UI Designers and UX Engineers and Researchers.&lt;/p&gt;

&lt;p&gt;There are Frameworks that can be used with anything and there are others that only can be used with specific JS Frameworks like Vue, React, Angular, Svelte, and others...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's a list of some of them:&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1- Frameworks Can be used anywhere
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://material.io/develop/web/docs/getting-started"&gt;Material Design&lt;/a&gt;: Google's Official Material Design Framework.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://materializecss.com/"&gt;Materialize&lt;/a&gt;: A Simple responsive front-end framework based on Material Design.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mdbootstrap.com/"&gt;Material Design for Bootstrap&lt;/a&gt;: A Material Design Framework Based on Bootstrap. It has its own CLI and Flexible to be used With JS Frameworks or Libraries. It has a Pro Version that contains extra components.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2- Frameworks Used with Specific JS Frameworks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://vuetifyjs.com/en"&gt;Vuetify&lt;/a&gt;: Vue Official Material Design Framework for built-in Vue Components. It's the one I am using.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://material-ui.com/"&gt;Material Ui&lt;/a&gt;: React components for faster and easier web development.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://material.angular.io/"&gt;Angular Material&lt;/a&gt;: Material Design components for Angular.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://sveltematerialui.com/"&gt;Svelte Material UI&lt;/a&gt;: Material UI Components for Svelte.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There a lot of other Frameworks that follow Google Material Design but can't mention all of them :-). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;You don't have to be a CSS hater to use Material Design Frameworks!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Something good to mention is there is a Library called &lt;a href="https://materialdesignicons.com/"&gt;Material Design Icons &lt;/a&gt; for Icons Check it out.&lt;/p&gt;

&lt;p&gt;If you are working in a company as a Frontend developer then usually there's a designer who designs Sketches that you have to turn into code and can't be done with Material Design Frameworks then I advise you to talk to him/her/them or your manager and tell them about Material Design and how it's great and how it delivers the best User Experience So they switch into those great guidelines. &lt;/p&gt;




&lt;p&gt;I hope you enjoyed this article :-)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://mobile.twitter.com/Amr__Elmohamady"&gt;@Amr__Elmohamady&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>design</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MEAN vs. MERN vs. MEVN Stacks ? What's the difference ?</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Sun, 06 Dec 2020 03:45:40 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/mean-vs-mern-vs-mevn-stacks-what-s-the-difference-29ge</link>
      <guid>https://dev.to/amrelmohamady/mean-vs-mern-vs-mevn-stacks-what-s-the-difference-29ge</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Full stack development&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, we have to know that those stacks are &lt;strong&gt;Full stacks&lt;/strong&gt; so you do the Frontend and the Backend.&lt;br&gt;
They are all JavaScript!&lt;br&gt;
The Frontend and the Backend will be done through JavaScript Frameworks.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Technologies you should know before the comparison&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JavaScript:&lt;/strong&gt; &lt;br&gt;
It's a programming (scripting) language used both on the client-side and server-side that allows you to make web pages interactive. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node.js:&lt;/strong&gt;&lt;br&gt;
It's a runtime environment that executes JavaScript outside the browser as writing Backend code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Express.js:&lt;/strong&gt; It is a back end web application framework for Node. It is designed for building web applications and APIs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;MongoDB:&lt;/strong&gt; It's noSQL (Json-like) database .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Angular:&lt;/strong&gt; It is a client side JavaScript framework was developed by Google.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt; It is a client side JavaScript framework was developed by Facebook.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Vue:&lt;/strong&gt; It is a client side JavaScript framework was developed by a single person Evan You who was working in Google.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What is the difference between them ?
&lt;/h3&gt;

&lt;p&gt;In those stacks there are common letters which are M - E - N .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;M&lt;/strong&gt;: MongoDB&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;E&lt;/strong&gt;: Express.js&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;N&lt;/strong&gt;: Node.js&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are the Backend technologies be while the Frontend technologies are A - R - V for MEAN - MERN - MEVN .&lt;/p&gt;

&lt;p&gt;Then Obviously,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A&lt;/strong&gt;: Angular&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R&lt;/strong&gt;: React&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;V&lt;/strong&gt;: Vue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, choose the stack that you love but before you have to learn the basics if web development which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML5&lt;/li&gt;
&lt;li&gt;CSS3&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;JS Dom and Bom&lt;/li&gt;
&lt;li&gt;ES6 Syntax&lt;/li&gt;
&lt;li&gt;SASS (optional but preferred)&lt;/li&gt;
&lt;li&gt;CSS Frameworks ( Bootstrap, Tailwind CSS, etc...)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://amrelmohamady.hashnode.dev/" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also buy me a coffee that would help :)&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/amrelmohamady" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What is Cross-site Scripting (XSS) ? Types of XSS!</title>
      <dc:creator>Amr Elmohamady</dc:creator>
      <pubDate>Thu, 03 Dec 2020 16:53:52 +0000</pubDate>
      <link>https://dev.to/amrelmohamady/what-is-cross-site-scripting-xss-types-of-xss-279p</link>
      <guid>https://dev.to/amrelmohamady/what-is-cross-site-scripting-xss-types-of-xss-279p</guid>
      <description>&lt;h2&gt;
  
  
  What is Cross-site Scripting?
&lt;/h2&gt;

&lt;p&gt;Cross-site Scripting (which is called XSS) is a type of security vulnerability typically found in web applications. XSS attacks enable attackers to inject client-side scripts into web pages viewed by other users. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So, Yes it's client side hacking not in Node.js but just plain JavaScript.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What attackers do is sending script-injected link to victims when victims open the link, the browser opens the site and also executes the XSS script which steal the user's data from session storage or cookies like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, sending the user's data to the attacker with an Http request.&lt;br&gt;
Here's an image which simplify the process:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqzmaks48fth79jchtv7h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqzmaks48fth79jchtv7h.png" alt="XSS Process" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Types of XSS:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1- Stored XSS
&lt;/h3&gt;

&lt;p&gt;Well, it's the simplest kind of XSS Attacks; XSS Script is sent to the database and called each time a page is loaded.&lt;br&gt;
&lt;strong&gt;Ex:&lt;/strong&gt;&lt;br&gt;
A comments section in a blog the attacker puts the XSS script and submit it as a comment so it appears each time the page is loaded to do its job.&lt;/p&gt;
&lt;h3&gt;
  
  
  2- DOM XSS:
&lt;/h3&gt;

&lt;p&gt;This kind is somehow tricky as this is the most one I like.&lt;br&gt;
It happens mostly in the URL using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When JavaScript takes data from an attack-controllable source (URL), and it passes it in the HTML using innerHTML which enables attackers to execute malicious scripts.&lt;/p&gt;

&lt;p&gt;For avoiding this type of XSS use innerTEXT instead of innerHTML, You may need to use innerHTML when you want to add dynamic HTML in your page so you can filter inputs from the Backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ex:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;a href="http://www.example.com/userdashboard.html?context=Mary"&gt;http://www.example.com/userdashboard.html?context=Mary&lt;/a&gt;&lt;/em&gt; is a dashboard customized for Mary. It contains the string Main Dashboard for Mary at the top.&lt;/p&gt;

&lt;p&gt;Here is how a DOM-based XSS attack can be performed for this web application:&lt;/p&gt;

&lt;p&gt;The attacker embeds a malicious script in the URL: &lt;em&gt;&lt;a href="http://www.example.com/userdashboard.html#context="&gt;http://www.example.com/userdashboard.html#context=&lt;/a&gt;SomeFunction(somevariable)&lt;/em&gt;.&lt;br&gt;
The victim’s browser receives this URL, sends an HTTP request to &lt;em&gt;&lt;a href="http://www.example.com"&gt;http://www.example.com&lt;/a&gt;&lt;/em&gt;, and receives the static HTML page.&lt;br&gt;
The browser starts building the DOM of the page and populates the document.URL property with the URL from step The browser parses the HTML page, reaches the script, and runs it, extracting the malicious content from the document.URL property.&lt;br&gt;
The browser updates the raw HTML body of the page to contain: Main Dashboard for&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="nc"&gt;SomeFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;somevariable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser finds the JavaScript code in the HTML body and executes it.&lt;/p&gt;

&lt;h3&gt;
  
  
  3- Reflected XSS (Non-persistent XSS):
&lt;/h3&gt;

&lt;p&gt;The most common way for cross-site scripting.&lt;br&gt;
Reflected XSS is not a persistent attack, so the attacker needs to deliver the link to each victim. These attacks are often made using social networks.&lt;br&gt;
In this case, the attacker’s payload has to be a part of the request that is sent to the web server. It is then reflected back in such a way that the HTTP response includes the payload(script) from the HTTP request. Attackers use malicious links, phishing emails, and other social engineering techniques to lure the victim into making a request to the server. The reflected XSS payload is then executed in the user’s browser.&lt;/p&gt;




&lt;h3&gt;
  
  
  How to discover various XSS types?
&lt;/h3&gt;

&lt;p&gt;Easiest way is to validate inputs and use an XSS Scanner.&lt;/p&gt;

&lt;p&gt;An Automated web security scanner checks your site for vulnerabilities. ... A website that's vulnerable to Cross-site scripting (XSS) will allow an attacker to inject browser-side scripts into web pages viewed by users.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dev.to/amrelmohamady"&gt;Follow the blog for more useful articles&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://mobile.twitter.com/Amr__Elmohamady"&gt;@Amr__Elmohamady&lt;/a&gt;&lt;/p&gt;

</description>
      <category>xss</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>html</category>
    </item>
  </channel>
</rss>
