Hey hava googled and tried every thing - but nothing seems to work, so now i will ask you guys:
How do i make my Node app. from stop exiting - when i like it to keep running and wait for response from a Web Socket connection? As you can see i have tried different stuff in the 'PreventExit' function. I simply want the app. to keep receiving data from the web socket connection - without closing/exiting.
var Gdax = require('gdax');
var WSemitter = require('../eventemitters/websocket-emitter');
module.exports = {
initws: function () {
var WebSocketEmit = new WSemitter();
test();
function test() {
try {
PreventExit();
var websocket = new Gdax.WebsocketClient();
websocket.on('message', function (data) {
console.log(data);
WebSocketEmit.fakeEvent();
});
}
catch (err) {
console.log(err);
}
}
function PreventExit(){
WebSocketEmit.on('fakeEvent', function () {
console.log('Just fake - to keep node running!');
});
setTimeout(function(){}, 100000);
process.stdin.resume();
}
}
}
UPDATE1:
My Web Socket provider CoinBase has recently updated their API. From Coinbase-exchange to Gdax. I just tried to replace:
var Gdax = require('gdax');
var CoinbaseExchange = require('coinbase-exchange');
//var websocket = new Gdax.WebsocketClient();
var websocket = new CoinbaseExchange.WebsocketClient();
and now my app waits! But after only 1 received json object my node app still exits!?? How do i make it keep the coonection open and not just shut down? But instead keeps receiving data from the API?
Update 2
When i remove all my test code and ONLY have the code related to the API, it works - BUT only with the old one...coinbase-exchange?? So it must be an error in there new (gdax)API or what? But no exception is thrown??
Please see the doc here:
https://www.npmjs.com/package/coinbase-exchange#websocket-client
https://www.npmjs.com/package/gdax#websocket-client
Further the DOC states (Which makes no sense - when it is only the old API which is the one still working):
GDAX transition As part of the rebranding of Coinbase Exchange to GDAX, API endpoints have changed. The old *.exchange.coinbase.com endpoints will continue working until Aug 24th, 2016. For the new endpoints see the documentation below.