当我使用 express router 中的以下代码时
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
});
我收到以下错误。
错误:发送后无法设置 header 。
当我删除行时
await anotherasyncfunction();
没有错误。
如何解决?我不能等待在 Express 路由器中使用 await 来解决的 promise 吗?
最佳答案
您可能对 express-promise-router 感兴趣,它封装了 express 路由器并允许您使用 async/await。
关于javascript - express router 不能等待一个 promise 来解析吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52324273/