【发布时间】:2018-09-17 12:30:17
【问题描述】:
我需要在我的 Express.js 中调用返回对象的异步回调函数,但我不知道怎么做!
app.get('/first', function (req, res, next) {
res.json(//put my async callback function here ?);
});
功能:
const reqObj = () => {
request(`isdb.pw/${url}`, function(err, res, body) {
if (!err) {
const $ = cheerio.load(body);
var name = $('meta[name="description"]').attr('content');
var story = $('meta[property="og:video:url"]').attr('content');
return {
name,
story
};
} else {
console.log(err);
}
});
};
【问题讨论】:
-
@KolaCaine 但我的函数不返回承诺,我该如何使用 .then ?
-
请发布您的功能
标签: javascript node.js express callback