Saturday, 27 May 2017

Return value from callback in function

Hello i would like to return a simple Boolean with there options: - true: user exists in database - false: user doesn't exists in database

Here's my non-working code:

database.users.get("test-username", function (err, value) {
    if (err) {
        return err;
    } else {
        return value;
    }
})

The return is always undefined I know that NodeJS is designed to work async, but async functions don't allow me to return something. I'm stuck, please help!

Also, i use LevelUP as database system. (if my problem have no solution, is there an other database system in NodeJS that allow synchronous?)

Thanks to the community!



via L.X

No comments:

Post a Comment