小编L.X*_*L.X的帖子

从函数中的回调返回值

您好,我想返回一个带有选项的简单布尔值: - true:用户存在于数据库中 - false:用户不存在于数据库中

这是我的非工作代码:

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

返回总是undefined 我知道 NodeJS 旨在异步工作,但是异步函数不允许我返回某些内容。我卡住了,请帮忙!

另外,我LevelUP用作数据库系统。(如果我的问题没有解决方案,NodeJS 中是否还有其他允许同步的数据库系统?)

感谢社区!

asynchronous return synchronous node.js

2
推荐指数
1
解决办法
8940
查看次数

标签 统计

asynchronous ×1

node.js ×1

return ×1

synchronous ×1