【发布时间】:2016-09-08 18:39:34
【问题描述】:
目前,当我在运行“node jkl.js”时在“exports.findOneProblem”中使用 console.log(result) 时,它可以工作。我能够看到结果。但是,当我使用 return 而不是 console.log() 时,我得到的只是控制台中的 Promise {pending}。请填补空白....学习如何使用 Promise,谢谢。
//asd.js
exports.findOneProblem = function(problemId) {
return RClient.authenticate(options).then(function (client) {
const Problem = client.Problem;
return Problem.findOne(problemId)
}).then(function(result){
return result
});
};
第二个文件:jkl.js
var okay = require('./asd');
var moneymoney = okay.findOneProblem(263)
console.log(moneymoney)
var honeyhoney = moneymoney.then(function(result){
return result
})
console.log(honeyhoney)
【问题讨论】:
标签: javascript node.js asynchronous promise