I have a server set up and client -> server events work great, server -> client events also work.
However, as I am writing to my DB I want to emit a server->server (or s
I understand where my logical misstep was at this point.
Socket.io is (as far as I can tell) a robust server->client->server event handler, and is really great at that. However I was looking to handle some events within the app itself. I found what I was here in NodeJs' documentation.
Changed code: I added:
var EventEmitter = require("events").EventEmitter;
var ee = new EventEmitter();
and within my socket event I have:
if (rows[0].rows === 0) {
console.log('gonna emit');
ee.emit('internal event', {'data': true})
return;
}
I then created a new section in my server for internal events, and that has:
ee.on("internal event", function (data) {
console.log(data)
});
Which is working great.
TL;DR: Socket.io is awesome for server->client->server interactions. Node's built in event handler is great for internal events.