【发布时间】:2020-05-11 18:49:34
【问题描述】:
我尝试了以下代码,因为节点是异步类型,以便按顺序运行我的代码,我添加了 then 函数,但我收到错误 TypeError: Cannot read property 'then' of undefined。我使用了下面的代码
va
r arr =[]
exceltojson({
input: 'test.xlsx',
output: 'test.json',// Don't need output
sheet: 'test'
},
function(err, result) {
if (err) {
console.error(err);
}
}
)
.then() {
// var msg ='done';
updateFlag();
})
function updateFlag(){
console.log('end')
}
I expect the output like
conversion done
end
【问题讨论】:
-
你的函数应该返回 Promise for
then工作当前它返回 undefined。请同时发布exceltojson -
你的函数应该返回promise,然后才能工作——你能分享一些参考吗
-
mongoose 本身就支持 Promise,你的库可能支持也可能不支持库
-
不使用promise return,有没有可能使这段代码连续?
标签: javascript node.js json