快递路由器不能等承诺解决吗?



当我从快速路由器使用以下代码时

var anotherasyncfunction = async() => {
var value = await settings.get("config"); // this is another async from a module.
console.log(value);
}
app.get("/api", async(req, res) => {
await anotherasyncfunction(); // This is another async function
//more code
});      

我收到以下错误。

错误:发送标头后无法设置标头。

当我删除该行时

await anotherasyncfunction(); 

没有错误。

如何解决?我不能等待在快速路由器中使用 await 解析的承诺吗?

您可能对 express-promise-router 感兴趣,它包装了 express 路由器并允许您使用 async/await。

https://www.npmjs.com/package/express-promise-router

最新更新