Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.get() requires callback functions but got a [object Undefined]

I am working with mongoose.

I wrote the following code in routes.js

var docs = require('../app/controllers/genericController');
    app.post('/newdoc', docs.createMainDoc);
    app.get('/listdoc', docs.listDocs);

and in genericController :

exports.listDoc = function(req, res) {
    var Model = mongoose.model(req.model); //i dont know, if this is defined or undefined. Actually i am not able to check it. Even if i comment whole body of this exports.listDoc, then also i get the same error. just assume here that here i am getting model.
    Model.find(function(err, models) {
        if (err) {
            res.render('error', {
                status: 500
            });
        } else {
            res.jsonp(models);
        }
    });
};

Bu i am getting error :

.get() requires callback functions but got a [object Undefined]

How to resolve it?

like image 709
codeofnode Avatar asked Sep 04 '13 14:09

codeofnode


1 Answers

You have docs.listDocs instead of docs.listDoc. That's why it's undefined.

app.get('/listdoc', docs.listDoc/*s*/);
like image 107
user2736012 Avatar answered Oct 16 '22 15:10

user2736012