Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:12:55+00:00 2026-06-11T05:12:55+00:00

I have setup myself a NodeJS and socket.io server with the mysql node module

  • 0

I have setup myself a NodeJS and socket.io server with the mysql node module and all works well.

Here is my script:

// create an http server listening on port 8100
var io = require('socket.io').listen(8100);
var mysql = require('mysql');

var connection = mysql.createConnection({
host     : '127.0.0.1',
user     : 'user',
password : 'password',
database : 'mybase'
});

connection.connect(function(e){
if(e)
{
    console.log('Database connection failed. ('+e+')') ;
}
else
{
    console.log('Database connection successful!') ;
}
})

connection.query('SELECT id, name FROM entity_details WHERE id = 4626', function(e, rows) {
if(e)
{

}
else
{
    console.log(decodeURIComponent(rows[0]['name'])) ;
}
 });

// listen on new connections
io.sockets.on('connection', function (socket) {

// listen on an event called "eventA"
socket.on('eventA', function(data) {
    // send "eventA" to all clients, except the sender
    io.sockets.emit('eventA', data);

});

});

My question is how do I get MySQL to “tell” nodeJS/Socket.io that values in the column have changed or new rows updated? So in effect I get a live view of whatever table, column etc I want in the database?

I figure I don’t want to poll the database every second as that defeats the whole idea of socket.io and I might as well use setTimeout with ajax calls.


After some thinking I have come up with this process that I think would be the most efficient for a real-time view, please see attached. Please let me know what you think!enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:12:57+00:00Added an answer on June 11, 2026 at 5:12 am

    I’m using postgresql but since mysql supports triggers, it should work the same.

    Put a trigger in each table on update
    subscribe to the events for each trigger on your database module

    for (notification in notifications) {
    var n =notifications[notification];
    pgclient.on('updated', n.handler);
    pgclient.query("LISTEN "+n.channel);
    }

    send message back

    socket.emit('eventA',dbMsg.payload);

    This way you don’t need to poll.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have myself a self-hosted WCF server setup, which serves a clientaccesspolicy.xml and an
My project setup is like this Server side I have webserver with PHP,MySQL database
i have setup an overlay script to enable me to display an overlay popup
I have setup Codeigniter on my server and I installed Grocery crud on it.
I have an automatic replacement done by my vim setup, which systematically replaces all
I have a database that stores images in a MySQL BLOB field. I setup
I'm working on a project myself. I have subversion setup and using tortoisesvn to
I have a very basic Symfony2.1 setup with FOSUserBundle installed. When registering all is
Ok, so I have gotten myself completely confused here. I am not sure why
I'm quite new to git. I have a repo setup on a server (A)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.