小编Ram*_*jan的帖子

3
推荐指数
1
解决办法
4455
查看次数

req.body 在 express 应用程序的 post 路由中未定义

这是我的路由器

router.post('/', async(req, res) => {

const posts = await loadPostsCollection()

await posts.insertOne({
    text: req.body.text,
    createdAt: new Date()
})
res.status(201).send()
})
Run Code Online (Sandbox Code Playgroud)

这是终端错误

在端口 3090 上进行列表 ..... (node:7764) UnhandledPromiseRejectionWarning: TypeError: 无法读取 /Users/macbook/Desktop/node-project/server/routes/api/posts.js:19 处未定义的属性“文本”: 24 在 processTicksAndRejections (internal/process/task_queues.js:94:5) (node:7764) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。这个错误要么是因为在没有 catch 块的情况下抛出了异步函数,要么是因为拒绝了一个没有用 .catch() 处理过的承诺。(rejection id: 1) (node:7764) [DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的承诺拒绝将使用非零退出代码终止 Node.js 进程。

javascript node.js express

3
推荐指数
1
解决办法
471
查看次数

标签 统计

database ×1

express ×1

javascript ×1

mysql ×1

node.js ×1

unicode ×1