<?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: Awa Eric Angelo</title>
    <description>The latest articles on DEV Community by Awa Eric Angelo (@ericblak_x).</description>
    <link>https://dev.to/ericblak_x</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%2F1701469%2F812c4ec5-d40c-40d0-b6c8-bef9155fd4a6.png</url>
      <title>DEV Community: Awa Eric Angelo</title>
      <link>https://dev.to/ericblak_x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ericblak_x"/>
    <language>en</language>
    <item>
      <title>Real-time chat communication for a messaging system with NodeJs and Socket.IO</title>
      <dc:creator>Awa Eric Angelo</dc:creator>
      <pubDate>Sat, 29 Jun 2024 01:39:55 +0000</pubDate>
      <link>https://dev.to/ericblak_x/real-time-chat-communication-for-a-messaging-system-with-nodejs-and-socketio-4ac</link>
      <guid>https://dev.to/ericblak_x/real-time-chat-communication-for-a-messaging-system-with-nodejs-and-socketio-4ac</guid>
      <description>&lt;p&gt;I'm going to be writing about a back-end problem I solved and give an overview of the step-by-step approach I took to solving that problem.&lt;/p&gt;

&lt;p&gt;Quite recently while working on implementing a messaging system and I faced an issue of making it a real-time communication system. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;The primary challenge was to create a messaging system that supports real-time communication between users. The requirements include having real-time updates meaning messages should appear instantly without the need for refreshing the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-Step Solution
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Choosing Appropriate Technologies&lt;/strong&gt;&lt;br&gt;
To build the real-time chat functionality, I opted for the following technologies&lt;br&gt;
&lt;strong&gt;- NodeJs&lt;/strong&gt; with &lt;strong&gt;Socket.IO&lt;/strong&gt; for the server-side real-time communication.&lt;br&gt;
&lt;strong&gt;- MongoDB&lt;/strong&gt; for persistent storage of the messages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Setting-up the server&lt;/strong&gt;&lt;br&gt;
I then set-up a server with NodeJs and socket.io&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%2Fuploads%2Farticles%2F073bm9q9314aiufa6gsw.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%2Fuploads%2Farticles%2F073bm9q9314aiufa6gsw.png" alt="Image description" width="463" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Implementing the logic to handle the real-time communication&lt;/strong&gt;&lt;br&gt;
Created 4 different events for this namely;&lt;br&gt;
&lt;strong&gt;Connection event&lt;/strong&gt; which is triggered whenever a client connects to the server&lt;br&gt;
&lt;strong&gt;JoinRoon event&lt;/strong&gt; which will allow user to join specific chat rooms&lt;br&gt;
&lt;strong&gt;Chatmessage event&lt;/strong&gt; which will handle incoming chats&lt;br&gt;
&lt;strong&gt;disconnect event&lt;/strong&gt; which is triggered when the user disconnects from the server&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%2Fuploads%2Farticles%2Fdlr7zf5go7l1xkafdgau.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%2Fuploads%2Farticles%2Fdlr7zf5go7l1xkafdgau.png" alt="Image description" width="463" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Creating a persistent storage for the Messages&lt;/strong&gt;&lt;br&gt;
To ensure messages are not lost and can be retrieved later, I used MongoDB for persistent storage.&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%2Fuploads%2Farticles%2Fy0snpsxcytssul782jw6.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%2Fuploads%2Farticles%2Fy0snpsxcytssul782jw6.png" alt="Image description" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Building this real-time chat application involved careful consideration of technologies and architecture and by leveraging NodeJs and Socket.io I was able to implement a messaging system that met my requirements.&lt;/p&gt;

&lt;p&gt;I'm a backend developer that loves building good and efficient systems. Being a problem solver, I love to learn new things and ways of doing things. And recently got accepted into an internship of an organization known as HNG and I know this internship is an opportunity for me to grow my skills as a developer by working on real-world projects, learning and gathering knowledge from experts in the field.&lt;br&gt;
So I really am super excited to be part of this internship which promises to be a wonderful journey. You can learn more about this internship here on &lt;a href="https://dev.tourl"&gt;https://hng.tech/internship&lt;/a&gt; or here &lt;a href="https://dev.tourl"&gt;https://hng.tech/hire&lt;/a&gt;. &lt;br&gt;
I really look forward to being one of the few to complete this internship so Wish me luck in my endeavour.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>backend</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
