title: Loading .js files on client side with page served by Node JS
body: <p>I have the following simple JS file, which will look familiar to anyone who's used Socket.IO with NodeJS and the Express framework:</p>
  
  <pre><code>var express = require('express'),
      app = express(),
      server = require('http').createServer(app),
      io = require('socket.io').listen(server);
  
  server.listen(8374);
  
  // routing
  app.get('/', function (req, res) {
      res.sendfile(__dirname + '/index.html');
  });
  </code></pre>
  
  <p>In <code>index.html</code>, I have the following line of code:</p>
  
  <pre><code>&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I have done some experimenting with pathnames and serving/mounting and I still don't really understand how this client-side line manages to work. The answer to <a href="https://stackoverflow.com/questions/12344622/how-does-node-serve-client-js-files">this question</a> says that by listening to the <code>server</code>, <code>io</code> handles all incoming Socket.IO requests.</p>
  
  <p>...</p>
  
  <p><strong>My question is:</strong> Can this be done for other client-side JS files?</p>
  
  <p>For example, is there some easy way to bundle up JQuery so that it can be handled in the same way? At the moment I can put the file in a folder like <code>public</code> and use Express' <a href="http://expressjs.com/api.html#app.use" rel="nofollow noreferrer"><code>app.use()</code> method</a> so that in <code>index.html</code> I can include this line:</p>
  
  <pre><code>&lt;script src="/public/jquery-1.9.1.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Is there a way to manage JQuery as a dependency as we can with NodeJS?</p>
  
  <p>I'm thinking the <strong>end result</strong> would look something like this:</p>
  
  <p>SERVER-SIDE:</p>
  
  <pre><code>var jquery = require('jquery');
  </code></pre>
  
  <p>CLIENT-SIDE:</p>
  
  <pre><code>&lt;script src="jquery/jquery-1.9.1.js"&gt;&lt;/script&gt;
  </code></pre>