using jQuery with socket.io
<p>I am trying to use jQuery in my socket.io js (index.js) file.</p>

<p>Whenever I try to do </p>

<pre><code>&lt;script src="http://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt;
&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt; 
&lt;script src="index.js"&gt;&lt;/script&gt;
&lt;script&gt;
  var socket = io();
  $('form').submit(function(){
    socket.emit('chat message', $('#m').val());
    $('#m').val('');
    return false;
  });
  socket.on('chat message', function(msg){
    $('#messages').append($('&lt;li&gt;').text(msg));
  });
  socket.on('new user', function(data){
    $('#newUserMessage').text(data);
  });        
&lt;/script&gt; 
</code></pre>

<p>I get this error in my console</p>

<pre><code>GET http://localhost:3000/index.js 

ReferenceError: $ is not defined
</code></pre>

<p>I'm not sure why this would happen?</p>

<p>But if I remove it I cant use jQuery's functions in index.js?</p>

<p><strong>My index.js file</strong></p>

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

var $usernameInput = $('.usernameInput');

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

io.on('connection', function(socket){
  socket.broadcast.emit('new user', 'New User Joined, Say Hi :D');
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

function setUsername () {
  username = cleanInput($usernameInput.val().trim());

  if (username) {
    socket.emit('add user', username);
  }
}
</code></pre>