title: Node.js: Removing users in Socket.IO
body: <p>i'm having problems in removing users in Socket.IO, upon their browser close the <code>user</code> in the array <code>users[]</code> is not removed and not updated and i would like also to update the users in the client side. Can you help me remove user programmatically? Here is my code guys, i hope you can help me with my code provided below. I've already surfed the net on how to remove users but i can't really make it work. Thanks in advance guys.</p>
  
  <p>Here is my <strong>server.js</strong>:</p>
  
  <pre><code>var redis = require('redis');
  var express = require('express');
  var app = express();
  var http = require('http');
  var server = http.createServer(app);
  var io = require('socket.io').listen(server);
  var publish = redis.createClient();
  var subscribe = redis.createClient();
  
  server.listen(8080);
  
  var users = [];
  app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
  });
  
  io.sockets.on('connection', function (socket) {
    socket.on('adduser', function (user) {
      users[user] = user;
      console.log(users);
    });
  
    socket.on('disconnect', function (user) {
      delete users[user] = user;
      io.sockets.emit('update', user);
  
      // delete users[user] = users;
      // socket.emit('update', users);
      console.log(users)
    });
  
    socket.on('update', function () {
      users[user] = user;
      console.log('Current users: ', users);
    });
  });
  </code></pre>
  
  <p>Here is my <strong>client.html</strong>:</p>
  
  <pre><code>&lt;html&gt;
  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    var socket = io.connect('http://localhost:8080');
    socket.on('connect', function(){
      socket.emit('adduser', prompt("What's your name?"));
    });
  &lt;/script&gt;
  
  &lt;div style="float:left;width:150px;border-right:2px solid black;height:510px;padding:10px;overflow:scroll-y;text-align:center;"&gt;
      &lt;b&gt;Users&lt;/b&gt;
      &lt;div id="users"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks again guys, i hope you can help me :)</p>