Displaying the number of connected users

How can I gather / display the number of concurrent users?

Something like the equivalent of:

socket.on('connect', function() { connectCounter++});
socket.on('disconnect', function() { connectCounter--});