I have studied communication between two (or more) servers raised in NodeJS via REST
más as I searched for content (references, explanations, benchmarks, etc.) I found indications of REST
would bring more cost to the process and WebSocket
would be more recommended, but all material I found was referring to client (front-end) for server (backend).
The very succinct question is: How to connect and exchange messages between two servers via sockets (backend only)?
The initial implementation where I used REST
worked with express to map routes and superagent to make requests.
Now when I try to use WebSocket
I'm using the uws module
example.js
var WebSocketServer = require('uws').Server;
var wss = new WebSocketServer({ port: 3000 });
function onMessage(message) {
console.log('received: ' + message);
}
wss.on('connection', function(ws) {
ws.on('message', onMessage);
ws.send('something');
});