server
io.on('connection', socket => {
console.log('Client connected');
socket.on('disconnect', () => {
console.log('Client disconnect')
})
})
app.get('/tenders', auth, (req,res) => {
connection.query("SELECT * FROM tenders", function(err, _res){
const id = _res.map(tenders => tenders.id);
const category = _res.map(tenders => tenders.category);
const description = _res.map(tenders => tenders.description);
const tender = {
id: id,
category: category,
description: description
}
res.sendFile(__dirname + '/tenders.html', () => {
io.emit('tender', tender);
});
})
});
client
var io = io('http://localhost:56026/tenders');
io.on('tender', (data) => {
console.log(data + ' - data');
$('.tenders').html(data.id[0])
});