Saturday, 12 January 2019

Any chance of some help for a noob?

I'm looking to build a project based on node that will have a few different websocket connections, I'm fine with the code itself for what I want to do but can't seem to get my head around how to start the websocket modules (code already written and moved to a file named ws.js) to run from the main server.js file.I have tried spawning as a child process but just getError: spawn ws.js ENOENT I have removed all other code from each file to prevent hidden errors, content of the files are below.Server.jsvar child = require('child_process').spawn('ws.js'); child.stdout.on('data', function (data) { console.log('stdout: ' + data); }); child.stderr.on('data', function (data) { console.log('stderr: ' + data); }); child.on('exit', function (code) { console.log('child process exited with code ' + code); }); setTimeout(function() { child.stdin.write('echo %PATH%'); }, 2000); ws.jsconst Gdax = require('gdax'); const publicClient = new Gdax.PublicClient(); const websocket = new Gdax.WebsocketClient(['BTC-USD', 'ETH-USD']); websocket.on('message', data => { /* work with data */ console.log("data received"); }); websocket.on('error', err => { /* handle error */ }); websocket.on('close', () => { /* ... */ }); Cheers

Submitted January 12, 2019 at 08:27PM by phillwilk

No comments:

Post a Comment