title: how to make a multiple node js chat like facebook?
body: <p>well, i have read some tutorials and i have a chat in node js with express and socket io, it works well!!
  so, the way it works is:
  a user that opens the url in the port 3000 connects and now cant send messages, if another user connects in the same url and port now can see the new messages an he can send messages too.
  i want to have multiple scenarios like this in the same app, to make something like facebook chat!!,
  thanks!</p>
  
  <p>this is the code i have:
  server side:</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  app.get('/', function(req, res){
  
  res.sendFile(__dirname+'/index.html');
  
  });
  
  io.on('connection', function(socket){
  console.log('a user connected');
  
  socket.on('chat message', function(msg){
  io.emit('chat message', msg);
  });
  
  
   socket.on('disconnect', function(){
  console.log('user disconnected');
  });
  });
  
  
  
  http.listen(3000, function(){
  console.log('listening on *:3000');
  });
  </code></pre>
  
  <p>in client side javascript:</p>
  
  <pre><code> var socket = io();
    $('form').submit(function(){
  
      socket.emit('chat message', {message: $('#m').val(), type_msg: 'chat_message'});
  
      $('#m').val('');
      return false;
    });
  
    socket.on('chat message', function(msg){
  
     switch(msg.type_msg){
         case "chat_message":
               $('#messages').append($('&lt;li&gt;').text(msg.message));
             break;
  
          case "user_is_typing":
              $('#status').val(msg.message);
              break;
  
          case "user_is_not_typing":
             $('#status').val(msg.message);
              break;
         }     
        });
  
  
    $('#m').keypress(function(){
  
      socket.emit('chat message', {message: "User is typing! :D",type_msg: "user_is_writing"});
    });
  
    $('#m').keyup(function(){
  
      socket.emit('chat message', {message: "User in thinking...",type_msg: "user_is_typing"});
    });
  </code></pre>