簡體   English   中英

當我創建一個發布請求然后發生錯誤.....錯誤=“錯誤”:“無法讀取未定義的屬性(讀取'名稱')”

[英]when I create a post request then Error occurs ..... the error = "error": "Cannot read properties of undefined (reading 'name')"

const ProductSchema={
name:{
    type: String
}} const Employee=mongoose.model('product',ProductSchema);catalogroute.post('/api/add catalogs', async(req,res)=>{
try{
    const user=new Employee({

        name:req.body.name
    });
   const val= await user.save();
    res.json(val);
   }
   catch(e){
       res.status(500).json({error: e.message});
   } } );

"error": "Cannot read properties of undefined (reading 'name')"

在 post 路由中,刪除 add 和 catalogs 之間的空格,或使用 '/api/add-catalogs'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM