i'm newbie in nodejs and i want to send data to client without send request from client, for example i want to after create new data in database like with mysql trigger nodjs fetch data from database and send necessary data to client. in other language programing we try to create Thread to fetch such as database or send JSON object every one secode, how to this ability in NodeJS?
var server = require('http').createServer(),
io = require('socket.io').listen(server),
mysql = require('mysql'),
express = require('express'),
fs = require('fs');
server.listen(3000, 'localhost');
console.log("connected...");
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'node'
});
io.listen(server).on('connection', function(client) {
/* FETCH DATA IF NECESSERY AND IF DATA INSERTED IN DB OR UPDATE OR DELETE*/
console.log("data send");
});