title: Uncaught ReferenceError: io is not defined
body: <p>i am new to node.js and try making a simple chat app with nodejs but i can't get this error " Uncaught ReferenceError: io is not defined ".
  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>nodejs file</p>
  
  <pre><code>var express = require('express'),
      app = express(),
      server = require('http').createServer(app),
      io = require('socket.io').listen(server);
  
  server.listen(2000);
  
  app.get('/',function(req,res){
      res.sendfile(__dirname + '/chat.html');
  });
  
  io.sockets.on('connection',function(socket){
      socket.on('send message',function(data){
          io.sockets.emit('new message',data);
      });
  });
  </code></pre>
  
  <p>and html file</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Chat with node and socket io&lt;/title&gt;
      &lt;style type="text/css"&gt;
          #chat{
              height: 400px;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="chat"&gt;&lt;/div&gt;
      &lt;form id="send_message"&gt;
          &lt;input id="message"/&gt;
          &lt;button type="submit"&gt;send&lt;/button&gt;
      &lt;/form&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script scr="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
      jQuery(function($){
          var socket = io.connect();
          var messageForm = $('#send_message');
          var messageBox = $('#message');
          var chat = $('#chat');
  
          messageBox.submit(function(e){
              e.preventdefault();
              socket.emit('send message',messageBox.val());
              messageBox.val('');
          });
  
          socket.on('new message',function(data){
              chat.append(data + "&lt;br/&gt;");
          });
      });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>