Hi, I am new to node and I was wondering how I can consume a websockets service from node, os server-server, the second is an external server here the link: link , Thank you very much community for your answers.
I suggest using the 'ws' library that is available in npm: npm install ws
. Then you can consume the websockets API in this way:
var WebSocket = require('ws');
var ws = new WebSocket("wss://ws.blockchain.info/inv");
ws.on('open', function() {
ws.send(JSON.stringify({"op":"ping"}));
});
ws.on('message', function(message) {
console.log('Received: ' + message);
});
ws.on('close', function(code) {
console.log('Disconnected: ' + code);
});
ws.on('error', function(error) {
console.log('Error: ' + error.code);
});