最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - .get() requires callback functions but got a [object Undefined] - Stack Overflow

programmeradmin7浏览0评论

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 ment 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?

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 ment 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?

Share Improve this question asked Sep 4, 2013 at 14:06 codeofnodecodeofnode 18.6k29 gold badges88 silver badges146 bronze badges 1
  • Means that docs.listDocs is undefined... – epascarello Commented Sep 4, 2013 at 14:10
Add a ment  | 

1 Answer 1

Reset to default 16

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

app.get('/listdoc', docs.listDoc/*s*/);
发布评论

评论列表(0)

  1. 暂无评论