Building an multi-user chat application

Debojyoti Paul
2 min readAug 12, 2018

Hi Guys. I am writing this short article about a chatroom application I developed while I was in college. This was really a fun project to do.

So , the application is very simple. User enters to the site. Join a session using a passcode. Acquires an unique user name. Then Either broadcasts messages or send private message to individuals.

So. simple right.

home page of the app

The above figure is the home screen of the app. It lists the available sessions and an user can click on session name, enter pass code and gain access. Also, in this page an admin can log in using the button on the left side of the screen.

I have used JWT for authentication. The application is stateless on the server side, and the session tokens are stored in local storage of the client.

jwt authentication code snippet

Once a user joins a session an api is called to display all the n most recent messages in this session.

Most recent messages extracted from db

After that socket.io comes to the picture. I love the library, as it provides powerful features with simple API’s. Of course for production grade apps you have to use a good pub/sub messaging library or develop your MqTT protocol like whatsapp.

code snippet for socket handling server side

Every Message that is broadcasted or send privately, is stored in a MongoDB instance hosted in a MLAB server.

And, finally the application is live in domain https://paul-chatroom.herokuapp.com.

Thanks to Heroku for providing the PaaS service which allowed me to deploy the app. Heroku is great and I recommend it to every beginner to try it.

So, that’s all for the chatroom application, which is small but a interesting project for me. I haved used technologies like NodeJs, Socket.io, jQuery, MongoDB and ExpressJs and platforms like MLab and Heroku.

The github link of the project is

Please fork and star the project. Thanks !

--

--