Function does not give result in NodeJS

I try to call a function i made to test if a username exist or not in the database.

The function work but when i try to call the function in the console to see the return), i always get undefined.

Here is my test function:

function testUsername(pseudo, uid) {

    User.findOne({username:pseudo}).exec(function (err, data) {

        if (err) {
            return 'Error fetching user database';
        else if((data == null || data == '') || data._id == uid)
            return 'ok';
            return 'error';


Here is the call :

var check = testUsername('blabla', 123456);

Source: javascript

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.