Using NodeJS for live viewing in real time using a database

I played with Nodejs and now wanted to know if I can create a live update for the view / page, as shown in this tutorial here

The above example applies to all users on the site, I want to target my updates for specific users.

Create an array storing all client sockets; a socket is created when users log in.

One more thing, how can I refresh a web page or view, if something is updated in the database, I poll the server every time?

Am I using a MySQL database if I were using Redis instead?

EDIT: One more question: I was wondering how the sites can check if the database fields have been updated or changed, or have they been updated, or to update the view or web page?

thanks

+4
source share
1 answer

Create an array that stores all client sockets, a socket created when users log in.

If you use the socket.io module to control the connection between clients and the server, you do not need to worry about the structure or the stored clients, since it will be managed for you in the background. It also offers various backups (including long polling) if client browsers do not support advanced vehicles such as WebSockets.

One more thing, how can I refresh a web page or view, if something is updated in the database, I poll the server every time?

DO NOT access the server every second, as transports such as long polling and WebSockets have been introduced to AVOID this. Since you will have constant communication between the client and the server with socket.io (which use methods and technologies, such as long polling or WebSockets), you can easily create an event system that updates or notifies specific clients about the changes when this happens .

I am using a MySQL database, should I use Redis instead?

Redis is a very good key / value repository for real-time data, frequently updated, which does not require a complex query. If you need advanced query support for your data, try, for example, looking at MongoDB .

+1
source

All Articles