1

I'm working on my first project using react and node and have been stuck on this problem for a while. I keep getting this error when trying to connect to my site using the ip address, but if I just do localhost:3000 it works perfectly. I want to be able to connect via the IP address so I can test it across devices. Here is the full error:

[HPM] Error occurred while trying to proxy request /socket.io/?EIO=3&transport=polling&t=N4EqtUl&sid=kz_I098ZM2h1Z6WZAAAI from 192.168.0.4:3000 to http://192.168.0.4:5000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)

I checkout out this post and implemented setupProxy.js like the second answer suggested, but it still isn't working.

Here is my node server (index.js):

const express = require('express');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
const path = require('path')

const port = process.env.PORT || 5000;
app.use(express.static(path.join(__dirname, 'client/build')));

io.on('connection', function(socket) {
    console.log('a user connected');
});

// Anything that doesn't match the above, send back index.html
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname + '/client/build/index.html'))
  })

http.listen(port || 5000, function () {
    console.log('listening on', port);
});

  • Try telling your node server to listen to any address, by default it might just be listening to `localhost`. Do: `app.listen(5000, '0.0.0.0')` instead of `app.listen(5000)`. – cbr Mar 25 '20 at 00:08
  • What should app be referring to? In my node server, I have it setup like something like this: ``` const express = require('express'); const app = express(); var http = require('http').Server(app); var io = require('socket.io')(http); const path = require('path') const port = process.env.PORT || 5000; app.use(express.static(path.join(__dirname, 'client/build')));l app.get('*', (req, res) => { res.sendFile(path.join(__dirname + '/client/build/index.html')) }) http.listen(port || 5000, function () { console.log('listening on', port); }); ``` – lettuceEater Mar 25 '20 at 00:19
  • You can edit your question to include your node code. – cbr Mar 25 '20 at 00:20
  • Thanks, just added my node server file. – lettuceEater Mar 25 '20 at 00:22
  • I'm referring to `http.listen`. – cbr Mar 25 '20 at 00:23
  • Still getting the error. Could it have to do with some type of security settings on my computer? – lettuceEater Mar 25 '20 at 00:27
  • Is it possible your firewall is blocking it? – Adam Coster Mar 25 '20 at 02:19

0 Answers0