title: Usage of socket.io and express js
body: <p>I am new to Node js and just now I come across through socket.io and express js, I want to know the difference between them or the relation between them. I am having some small codes that was used for the chat application</p>
  
  <p>In the nodeClient.js</p>
  
  <pre><code>var socket = io.connect( 'http://localhost:8080' );
  
  $( "#messageForm" ).submit( function() {
  
  var nameVal = $( "#nameInput" ).val();
  var msg = $( "#messageInput" ).val();
  alert("msg");
  socket.emit( 'message', { name: nameVal, message: msg } );
  
  // Ajax call for saving datas
  $.ajax({
  url: "./ajax/insertNewMessage.php",
  type: "POST",
  data: { name: nameVal, message: msg },
  success: function(data) {
  
  }
  });
  
  return false;
  });
  
  socket.on( 'message', function( data ) {
  var actualContent = $( "#messages" ).html();
  alert(actualContent);
  var newMsgContent = '&lt;li&gt; &lt;strong&gt;' + data.name + '&lt;/strong&gt; : ' + data.message + '&lt;/li&gt;';
  var content = newMsgContent + actualContent;
  
  $( "#messages" ).html( content );
  });
  </code></pre>
  
  <p>and in the nodeServer.js</p>
  
  <pre><code>var socket = require( 'socket.io' );
  var express = require( 'express' );
  var http = require( 'http' );
  
  var app = express();
  var server = http.createServer( app );
  
  var io = socket.listen( server );
  
  io.sockets.on( 'connection', function( client ) {
      console.log( "New client !" );
  
      client.on( 'message', function( data ) {
          console.log( 'Message received ' + data.name + ":" + data.message );
  
          //client.broadcast.emit( 'message', { name: data.name, message: data.message } );
          io.sockets.emit( 'message', { name: data.name, message: data.message } );
      });
  });
  
  server.listen( 8080 );
  </code></pre>
  
  <p>Now, coming to the ponit of my doubt</p>
  
  <p>in the nodeServer.js file, I have </p>
  
  <pre><code>var socket = require( 'socket.io' );
  var express = require( 'express' );
  var app = express();
  var server = http.createServer( app );
  
  var io = socket.listen( server );
  </code></pre>
  
  <p>I can observe there is some relation here between socket and express, Can anyone please explain me the relation and the usage of those two.</p>
  
  <p>This will help me to move further into more node js applications</p>
  
  <p>thanks!</p>