Basically, you would watch when the user writes in the username input field( using the keyup event) and send the value of the input field to the server using socket.io, on the server, when you receive the value in the event you will do a query on the database(model.findOne in mongoose) with that value and return the user if he exists. The key here is to make the database do an index on the username for a faster search by making the username field unique in mongoose or by creating a new index manually.
Example:
Frontend with jquery:
$(document).ready(function() {
var username = $('#username');
username.keyup(function() {
var value = username.val();
socket.emit('find_user', value);
});
});
socket.on('find_user_result', function(user) {
// treat result here
});
Backend with mongoose:
socket.on('find_user', function(value) {
User.findOne({username: value}, function(err, user) {
if (err) throw err;
if (!user) socket.emit('find_user_result', {});
else socket.emit('find_user_result', user);
});
})