Can't get nodejs socket.io work on my ubuntu virtual machine
<p>I'm trying to get my nodejs socket.io app work in my site with no results. On my own computer it works fine with xampp.  </p>

<p><code>npm install --save express@4.10.2</code> and <code>npm install --save socket.io</code> are installed</p>

<p>Here's my code: server.js that I run with nodejs</p>

<pre><code>var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );

var app = express();
var server = http.createServer( app );

var port = 8080;

var io = socket.listen( server );

io.sockets.on( 'connection', function( client ) {
    console.log("New user connected");

    client.on('message', function( data ) {
        console.log( 'Message: ' + data);

        io.sockets.emit( 'message', data);
    });
});

server.listen(port, function(){
    console.log("Listening on port: " + port);
});
</code></pre>

<p>Here's my index.php</p>

<pre><code>&lt;script src="script/node_modules/socket.io-client/dist/socket.io.js"&gt;&lt;/script&gt;
&lt;script&gt;
    var socket = io.connect( 'http://localhost:8080' );
&lt;/script&gt;
</code></pre>

<p>I'm doing this differently than <a href="http://socket.io/get-started/chat/" rel="nofollow noreferrer">this</a> because I'm using apache.</p>

<p>I'm getting this error no matter is the <code>server.js</code> running with nodejs or not I always get this same error.</p>

<p><a href="https://i.stack.imgur.com/Xoe9y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xoe9y.png" alt="enter image description here"></a></p>

<p>Virtual machine is from digitalocean. </p>

<p>All ports was blocked but 22, 80 and 443. </p>

<p>I allowed port 8080 with <code>sudo ufw allow 8080</code> and <code>sudo ufw allow out 8080</code> but it didn't work.</p>

<p>ufw was disabled <code>sudo ufw disable</code> but didn't work.</p>

<p>I have no idea what to try next. How do I fix this?</p>