express - Keep getting this error: Error: Route.post() requires callback functions but got a [object Undefined] -
i trying set react express application mongo db database. in preliminary stages , keep coming across error:
error: route.post() requires callback functions got [object undefined]
here 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 , name 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);
my routes right here. testing see if there correct connection.
const authcontroller = '../controllers/auth_controller'; const express = require('express'); const authroutes = express.router(); authroutes.post('/',authcontroller.signup) module.exports = authroutes;
my controller listed below:
const authcontroller = {}; authcontroller.signup = function(req,res,next) { console.log('here'); res.json({ user: "doesnt matter", data: 'put user profile on route' }); } module.exports = authcontroller;
not sure if mongo problem since first time using it, connection database works robo 3t check whats in database , user schema there. if comment out 1 route in routes page, errors go away.
i believe problem here:
const authcontroller = '../controllers/auth_controller'; authroutes.post('/',authcontroller.signup)
note authcontroller
string. i'm guessing intended:
const authcontroller = require('../controllers/auth_controller');
Comments
Post a Comment