node.js - 我收到 TypeError: Cannot read property 'numberOfSuits' of undefined 当我运行下面的代码在我的 firebase 数据库上发布新订单时
问题描述
下面的代码在邮递员上返回类型错误(TypeError:无法读取未定义的属性“numberOfSuits”)。此外,当我删除最后三个字段以仅发布前两个字段(默认)时,数据将写入数据库,但我在控制台中收到错误“TypeError:res.json is not a function”
app.post('/order', (res, req) => {
const newOrder = {
orderCode: 'OOR-0006',
status: 'In progress',
numberOfSuits: req.body.numberOfSuits,
neighborhood: req.body.neighborhood,
houseDetails: req.body.houseDetails
}
db
.collection('orders')
.add(newOrder)
.then(doc => {
res.json({message: `New order ${newOrder.orderCode} created succesfully!`})
}).catch(err => {
console.error(err);
});
});
解决方案
我认为改变
(res, req)
至
(req, res)
将解决问题
推荐阅读
- python - 查找与给定数字具有最接近值的行
- asp.net-core - 没有可用的架构 graphiql aspnet 核心
- node.js - 用户在节点 js 中提交后如何显示验证消息错误?
- shell - 匹配后删除字符串并排除空换行符
- docker-compose - 在 docker 中使用标签配置 traefik 不起作用?
- python - 我可以在不创建新列表的情况下缩短此冒泡排序吗?
- php - 如何使用php从数组中随机显示DIV
- sql - 将 char 数据类型转换为 datetime 数据类型导致超出范围的 datetime 值
- javascript - 如何选择所有可见的html
- android - 网络提供商位置始终返回 false(已禁用)