August 16, 2015 7:11 pm

How to Create Real-time Chat Application with Node.js Part 1

In the next tutorials, we will be building a simple Node.js chat application. Messages will be delivered in real-time and we are going to take advantage of the Speech Synthesis API for the supporting browsers so that the computer can read aloud the messages as they arrive in the chat. We will be using Node.js, Express and Redis for persistence. Express is a very popular framework for Node.js that eases development and provides many useful features.Create Real-time Chat Application with Node

Redis is a key-value data store which uses the machine memory to cache key-value pairs. Because our application would not save all the chat history and will keep only around 20 messages at a time I believe Redis is a good choice as the fact that it stores the data in memory makes it really efficient and quick. We will be using cloud hosting (Redis Labs) for our database and Heroku (another cloud provider) for our application.

In the public/views folder we have only one view for this application: index.html.

The markup

In the head tag we load jQuery, Bootstrap and the client-side part of Socket.io from CDNs, then we load our app’s unique stylesheet.

We create two boxes – the first taking 5 out of 12 columns on medium screens (it represents a box pinpointing the number of users online and their nicknames) and another box which takes 7 out of the 12 columns on medium screens which represents the chat itself.

On the bottom, there is a form with which users can add new messages to the chat:

The styles

Our styles give the two boxes (users online and the chat container) fixed dimensions and set the vertical overflow to scroll so that when there are many users or many long messages the users could scroll only the boxes to see what is inside. We also make some decorative modifications to the default boxes.

Part 2: How to Create Real-time Chat Application with Node.js Part 2

Part 3: How to Create Real-time Chat Application with Node.js Part 3

Part 4: How to Create Real-time Chat Application with Node.js Part 4

Author Ivan Dimov

Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter


Tutorial Categories:
  • Saeed Ansari

    Please explain in deep about auto refreshing front end and getting response from database its the hardest thing please explain as much as you can that part when time will come