【发布时间】:2019-07-02 04:23:31
【问题描述】:
无法在回调范围之外存储值
我尝试在回调范围之外声明一个数组、一个对象和一个空变量,但没有任何效果。
router.post('/login', async (req, res, next) => {
try {
const user = await users.view('viewEmailandPassword', 'email', {keys: [`${req.body.email}`], include_docs: true},
function(err, body) {
if (!err) {
body.rows.forEach(function(doc) {
console.log(doc.value)
// return doc.value
});
}
});
console.log(user) <--- nothing is returned
}
catch(err){
next(err)
console.err(err, "this is the error")
}
})
我得到“未定义”的输出
【问题讨论】:
标签: callback couchdb couchdb-nano