How to cleanly disconnect from a namespace in socket.io?

I have been trying to disconnect from a namespace or even from the main socket connection itself but have been failing. Below is my code Server Side: socket.on('userDisconnect', function () { ...