【发布时间】:2018-01-14 22:39:38
【问题描述】:
我正在尝试将 Node.js id 添加到从数据库检索到的会话中。 我为此目的编辑了蒸汽登录,但除了传递 id 之外的所有内容都有效。我知道为什么它不起作用。这是因为 node.js 中的查询是异步的。不幸的是,我不知道如何解决它,在函数中返回它。
req.user = user;
connection.query("select * from users where steamid = "+user.steamid, function(err, row){
if(err) {
throw err;
} else {
req.user.id = row[0].id;
//And now when i trying to console.log(req.user.id) i will se the id from database.
}
});
//But here when i try console.log(req.use.id) i see undefined.
我需要从数据库中设置req.user.id = id。
我做不到,因为这行不通。
【问题讨论】:
标签: mysql node.js variables steam-web-api