No.of Users in Socket.io Namespace

Is there any built-in way to find out number of users connected to a particular namespace in Node.js server that uses Socket.io?

There can be better ways but this should work :

Object.keys(io.of('/chat').manager.handshaken).length       //handshaken clients
Object.keys(io.of('/chat').manager.connected).length        //connected clients
Object.keys(io.of('/chat').manager.open).length             //open clients
Object.keys(io.of('/chat').manager.closed).length           //closed clients

You can replace /chat with your namespace. Namespace must start with a /. These are objects in the socket.io object io which store connected users (do console.log(io.of('/chat').manager.connected) to see the object).

Update

The easier way io.of('/chat').clients().length. See io.of('/chat').clients() to get all connected user details.