Cannot load socket.io.js file when using electron
<p>I am trying to make a chat application using Node.js with Electron and Socket.io, but when I try to load <code>/socket.io/socket.io.js</code>, I always get the error:</p>
<blockquote>
<p>Failed to load resource: net::ERR_FILE_NOT_FOUND</p>
</blockquote>
<p>If I just start the server on port 3000 and put</p>
<pre><code>res.sendFile(__dirname+&quot;/index.html&quot;);
</code></pre>
<p>then  socket.io.js can be loaded, but if I use electron and put</p>
<pre><code>mainWindow.loadURL(&quot;File://&quot;+__dirname+&quot;/index.html&quot;);
</code></pre>
<p>then the it gives me the above mentioned error.</p>
<p>here is the code for my index.js page:</p>
<pre><code>const electron = require('electron');
const {app, BrowserWindow} = electron;

app.on('ready', function(){
  var mainWindow = new BrowserWindow({
    width: 1400,
    height: 800
  });

  mainWindow.loadURL(&quot;File://&quot;+__dirname+&quot;/index.html&quot;);
  mainWindow.toggleDevTools();
});
</code></pre>
<p>here is my server.js page:</p>
<pre><code>var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);

users = [];
connections = [];

server.listen(process.env.PORT || 3000, &quot;localhost&quot;);
console.log(&quot;Server running...&quot;);

app.get('/', function(req,res){
  res.sendFile(__dirname+&quot;/index.html&quot;);
});

io.sockets.on('connection', function(socket){
  connections.push(socket);
  console.log('Connected: %s sockets connected', connections.length);

  //Disconect
  socket.on('disconnect', function(data){
    connections.splice(connections.indexOf(socket), 1);
    console.log('Disconnected: %s sockets connected', connections.length);
  });

  //Send message
  socket.on('send message', function(data){
    console.log(&quot;Message Received&quot;);
    io.sockets.emit('new message', data);
  });
});
</code></pre>
<p>And here is my index.html page:</p>
<pre><code> &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Chat Server&lt;/title&gt;
    &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;link rel = &quot;stylesheet&quot; href=&quot;./style.css&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;chat&quot;&gt;&lt;/div&gt;
    &lt;form id=&quot;info&quot;&gt;
      &lt;textarea placeholder=&quot;Message&quot; col=&quot;50&quot; id=&quot;message&quot;&gt;&lt;/textarea&gt;
      &lt;input type = &quot;submit&quot; value=&quot;Send&quot;&gt;&lt;/input&gt;
    &lt;/form&gt;
    &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;/socket.io/socket.io.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
    var socket = io.connect();
      $(function(){
        var socket = io.connect();
        var messageForm = $(&quot;#info&quot;);
        var message = $(&quot;#message&quot;);
        var chat = $(&quot;#chat&quot;);

        messageForm.submit(function(e){
          e.preventDefault();
          console.log(&quot;A message has been submited.&quot;);
          socket.emit('send message', message.val());
          message.val(&quot; &quot;);
        });

        socket.on('new message', function(data){
          chat.append(&quot;&lt;div class='chat-message'&gt;&lt;div class='chat-user'&gt;Max Braun&lt;/div&gt;&lt;div class='chat-text'&gt;&quot;+data+&quot;&lt;/div&gt;&lt;div class=''&gt;8/30/1999 at 8:33 PM&lt;/div&gt;&lt;/div&gt;&quot;);
        });
      });
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>