title: How to include Socket io in external js file linked to html file?
body: <p>I am using node js, socket io, and express to create a multiplayer web game.
  When the server start I listen on port 2000.
  When I go to <code>localhost:2000</code>, the file <code>lobby.html</code> is sent using</p>
  
  <pre><code>//app.js
  const express = require('express');
  const app = express();
  const serv = require('http').Server(app);
  app.get('/', function(req, res) {
      res.sendFile(__dirname + '/Client/lobby.html');
  });
  serv.listen(2000);
  var io = require(socket.io)(serv, {});
  </code></pre>
  
  <p>I would include the js for the lobby.html file inside the html file instead of using <code>&lt;script src='lobby.js&gt;</code>. </p>
  
  <p>I would also import socket io and the <code>app.js</code> file which is the server file in the lobby.html file.
  It looked like this:</p>
  
  <pre><code>&lt;script src='https://cdn.socket.io/socket.io-1.4.5.js'&gt;&lt;/script&gt;
  &lt;script src='../app.js'&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Since the js was written in the html file and socket io was included on that html page I could use <code>var socket = io();</code> in my js so I can communicate with the server(app.js).</p>
  
  <p>However, I want the js that was written in <code>lobby.html</code> to be moved to a file called <code>lobby.js</code> using <code>&lt;script src='lobby.js'&gt;</code> in the html file and also by using <code>require(./lobby.js)</code> in app.js. When I try to do <code>var socket = io()</code> in the <code>lobby.js</code> file, I get an error saying <code>io()</code> is not defined since the js file is separate from the html file.</p>
  
  <p>How can I get socket io to work in the <code>lobby.js</code> file.</p>
  
  <p>Incase you need the file structure, here it is:</p>
  
  <pre><code>-Game Folder
      -Client
          -lobby.html
          -lobby.js
      -app.js
      -package.json
  
  </code></pre>