2017-10-16 2 views
0

ルートを使用しようとしていますが、エラーが発生しています。.postにはコールバック関数が必要ですが、[オブジェクトが定義されていません]

経路がないので、経路に問題がある可能性があります。 私を助けてもらえますか?

index.js(ルートフォルダ)

module.exports = function(events){ 
       var mongoose = require('mongoose'); 
       var loadSchema = require('../schemas/index'); 
       var functions={}; 
       // save function 
       functions.saveEvent = function (req, res) { 
     //schema loading 
      new loadSchema({ 
       name:req.body.organizer, 
       email:req.body.email, 
       address:req.body.address, 
       street:req.body.street, 
       price:req.body.price, 
       category:req.body.category, 
       otherInfo:req.body.otherInfo 
      }).save(function(error,data){ 
       if(error) 
        res.json(error); 
       else 
        res.send("Event Saved"); 
      }); 
     }; 
      return functions; 
     } 

app.js

app.post('/addEvent',routes.saveEvent); // addEvent is the action of form 

index.js(スキーマフォルダ)

var mongoose = require('mongoose'); 

    module.exports = mongoose.model('user', { 
     name: Number, 
     email: String, 
     favoriteBook: String, 
     password: String, 
     confimrPassword: String 
     }); 


    module.exports=mongoose.model('event',{ 
     organizer:String, 
     email:String, 
     address:String, 
     street:String, 
     category:String, 
     price:String, 
     otherInfo:String 
    }) 

Error: .post requires callback functions but got a [object Undefined]

+0

あなたの投稿をより良くフォーマットしてください。何が起こっているのかを読むのは本当に難しいです。 – OArnarsson

答えて

0

index.js(routesフォルダ)は、他のミドルウェア関数を返す関数を公開しています。ミドルウェア関数にアクセスしたい場合は、エクスポートされた関数を索引に呼び出す必要があります。 JS:( '/ addEvent'、ルート()saveEvent)

変更app.post('/addEvent',routes.saveEvent); app.postに、

関連する問題