2017-09-14 11 views
0

データベースとしてmongo dbを使用してレスポンスエクスプレスアプリケーションを設定しようとしています。私は予備的な段階にいると、このエラーを越えてくる:ここエラー:Route.post()にコールバック関数が必要ですが、[オブジェクトが未定義です]

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

は私のルートは右ここにいる私のapp.js

const express = require('express'); 
// const http = require('http'); 
const bodyParser = require('body-parser'); 
const morgan = require('morgan'); 
const app = express(); 
const mongoose = require('mongoose'); 

mongoose.Promise = global.Promise; 


//db and name is auth 

mongoose.connect('mongodb://localhost/auth', { 
    useMongoClient: true, 
    /* other options */ 
    }); 
// app setup 

//server setup 

const port = process.env.Port || 4000 
// const server = http.createServer(app); 
app.listen(port); 
console.log(`Sever listening on ${port}`) 

const authRoutes = require('./routes/auth_routes'); 
app.use('/',authRoutes); 

です。私は正しい接続があるかどうかを調べるだけです。

const authController = '../controllers/auth_controller'; 
const express = require('express'); 
const authRoutes = express.Router(); 


    authRoutes.post('/',authController.signup) 



module.exports = authRoutes; 

私のコントローラは、以下に記載されています。それはそれを使用して私の最初の時間ですが、データベースへの私の接続をしていただきましチェックするロボ3トンを動作しますので、Mongoのが問題である場合

const authController = {}; 

authController.signup = function(req,res,next) { 
    console.log('here'); 
    res.json({ 
     user: "doesnt matter", 
     data: 'Put a user profile on this route' 
     }); 
} 

module.exports = authController; 

わかりませんデータベースとユーザースキーマがあります。ルートページの1つのルートをコメントアウトすると、エラーは消えてしまいます。

+0

何かをインポートすることを忘れてしまったため、これは単純なエラーですので、質問を削除してください。 –

答えて

2

私はこの問題はここにあると信じて:

const authController = '../controllers/auth_controller'; 

authRoutes.post('/',authController.signup) 

authControllerは単なる文字列であること。

const authController = require('../controllers/auth_controller'); 
+0

うわー.....なんて愚かな間違いだよ、私は何時間もコーディングしてきた。ポイントをいただきありがとうございます!私は必要を忘れてしまったことさえ気づかなかった。 – jdip88

関連する問題