我可以发布我的数据,但无法使用 body-parser 显示它

问题描述 投票:0回答:1
html node.js express handlebars.js body-parser
1个回答
0
投票

您的

Daily.create
是一个异步任务,因此您的
res.redirect("/daily")
可能会在数据保存到数据库之前在事件循环中执行。一个简单的改进是使用
async/await
模式,如下所示:

router.post("/daily_prog" , async (req,res) => { //< Mark as async function
    //...
    //await the create call
    await Daily.create({
        ...req.body,
        daily_image: `/img/dailyimages/${daily_image.name}`,
        
    });
    //...
    res.redirect("/daily")
})

© www.soinside.com 2019 - 2024. All rights reserved.