04-01-2019 11:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-01-2019 11:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Hello, a year ago I transferred data from companion to a server with this code:
// Listen for the onmessage event messaging.peerSocket.onmessage = function(evt) { // Output the message to the console console.log(JSON.stringify(evt.data)); // Send information to the server fetch('https://XXXX.es:3000/heartRate', { method:'post', headers: { 'Content-Type': 'application/json' }, body:JSON.stringify(evt.data) }).then(function(result) { if (!result.ok) { console.log(result.status + ': ' + result.statusText); return; } console.log('Enviado paquete'); }).catch(function (err){ console.log(err) }) }
Now i can't use that server anymore and i would like to fetch to localhost:3000. It's where my nodeJS server can listen
//nodeJS server.js code [...] https.createServer(options, app).listen(port, (err) => { if (err) { return console.log('something bad happened', err) } console.log(`server is listening on ${port}`) }); [...]
Is there a possibility to send data to my localhost through the companion? Later I need to insert that data in a mongo database with that server.js
04-01-2019 11:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-01-2019 11:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
The companion runs on the phone, so "localhost" is the phone. You'd need your phone and computer to be on the same network, then use the ip address of your computer instead of localhost.
