title: Uncaught ReferenceError: io is not defined
body: <p>I know this is an error talked about a lot in here. But after a few posts found via google it still didn't solve my problem.</p>
  
  <p>I get the above error when trying to include the io javascript in my index.html.</p>
  
  <p>I've tried:
  <code>&lt;script src="http://localhost:8080/socket.io/socket.io.js"&gt;&lt;/script&gt;</code>
  And <code>&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;</code></p>
  
  <p>And even tried switching the port to 3000. The problem still persists nonetheless.</p>
  
  <p>I've tried restarting my app.js and reinstalling socket.io(Although it is in my package) with <code>npm install socket.io</code>. I see that a socket.io folder is created in my node_modules folder.</p>
  
  <p>I start my server as following:</p>
  
  <pre><code>var express = require('express');
  
  var app = express(), 
      server = require('http').createServer(app),
      io = require('socket.io').listen(server);
  
  app.listen(8080);
  </code></pre>
  
  <p>And my index also loads the latest jQuery from Google: <code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt;</code></p>
  
  <p>My terminal shows that socket.io is started when i restart my app.js:</p>
  
  <pre><code>23 Jun 13:31:56 - [nodemon] starting `node app.js`
     info  - socket.io started
  </code></pre>
  
  <p>My index.html in total(I retyped/remodeled it from a tutorial: <a href="http://psitsmike.com/2011/09/node-js-and-socket-io-chat-tutorial/" rel="nofollow">http://psitsmike.com/2011/09/node-js-and-socket-io-chat-tutorial/</a>)</p>
  
  <pre><code>&lt;script src="http://localhost:8080/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
      var socket = io.connect();
  
      socket.on('connect', function() {
          socket.emit('adduser', prompt("Hoe heet je?"));
      });
  
      socket.on('updateChat', function(username, data) {
          $('#conversation').append('&lt;strong&gt;' + username  + '&lt;/strong&gt; says: ' + data + '&lt;br&gt;');
      });
  
      socket.on('updateUsers', function(data) {
          $('#users').empty();
          $.each(data, function(k, v) {
              $("#users").append('&lt;div&gt;' + k + '&lt;/div&gt;');
          });
      });
  
      $(document).ready(function() {
          $('#datasend').click(function() {
              //get the message and empty the input
              var msg = $('#data').val();
              $('#data').val('');
  
              //Let the server execute sendchat along with the msg
              socket.emit("sendChat", msg);
          });
  
          //ENTER key
          $('#data').keypress(function(e) {
              keyCode = (e.keyCode ? e.keyCode : e.which);
              if (keycode == 13) {
                  $(this).blur();
                  $('#datasend').focus().click();
              }
          });
      });
  
  &lt;/script&gt;
  &lt;div style="float:left;width:100px;border-right:1px solid black;height:300px;padding:10px;overflow:scroll-y;"&gt;
      &lt;b&gt;USERS&lt;/b&gt;
      &lt;div id="users"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div style="float:left;width:300px;height:250px;overflow:scroll-y;padding:10px;"&gt;
      &lt;div id="conversation"&gt;&lt;/div&gt;
      &lt;input id="data" style="width:200px;" /&gt;
      &lt;input type="button" id="datasend" value="send" /&gt;
  &lt;/div&gt;
  </code></pre>