Thanks to the success of my previous post about a Node.js push notification server, now in this post I would go further realizing a server that is able to read from a MySql database and then stream those data via websocket to many client connected on the same page. The idea behind this shit is that we will broadcast our data without having any timer on the client but only a ( kind of )timer on the server.
First of all we must install the modules needed for this example.
This node js module is needed to read a MySQL database
And then Socket.io to deal with the HTML5 websocket
The first part of our code is needed to set up the connection with database and to load the html ( client.hmtl ) page in which we are going to print the data fetched with our MySql queries.