Hi I'm building a web app that updates the user via socket.io how many tasks users have created on the website. I'm using socket.emit on the node.js side that will send a message to the angularjs client everytime a client creates a new task. However the codes doesn't execute, specifically the code inside this block in the node.js file:
console.log('a');
io.sockets.on('connection', function(socket) {
console.log('b');
io.sockets.emit('send', statinfo);
});
console.log('c');
When I look at the console I see "a" and "c" but not "b", as "b" is in that block of code that doesn't execute.
Here the rest of my code:
nodeapp.js (retrieves the numbers of tasks on the website)
app.post('/api/addtasks',function(req, res){
/*code to add tasks above*/
Stat.update(
{_id: statid},
{$inc: {'quantity': 1}},
function(err) {
console.log('test');
Stat.find({}, function(err, docs2) {
var statinfo = docs2;
io.sockets.on('connection', function(socket) {
io.sockets.emit('send', statinfo);
});
});
});
});