首页 > 解决方案 > 我收到 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);
    });
});

标签: node.jsfirebaseexpress

解决方案


我认为改变

(res, req)

(req, res)

将解决问题


推荐阅读