【发布时间】:2021-05-23 20:06:45
【问题描述】:
我想通过发布者功能向 nats 流媒体服务器发送数据。为此,我需要一秒钟然后在猫鼬模型保存上起作用。但是当我第二次调用 then() 函数时,
then(result => {}) 结果返回为未定义。
todo.save().then(result =>{
console.log(result)
res.status(201).json({
message : "done",
todo : result
});
}).then(result =>{
console.log(result); // ===> this return undefined
//natsPublisher(result.title, result.context); ===> I want to send this info to nats streaming
})
.catch(err=>{
console.log(err);
res.status(500).json({
message : "There is an error"
})
})
我该如何解决这个问题?也许我的结构很糟糕。如果很糟糕,请告诉我。
【问题讨论】:
标签: javascript node.js express mongoose promise