Node.js 错误:.get()需要回调函数,但在编写ToDo应用程序时获得了[object Undefined]-

Node.js 错误:.get()需要回调函数,但在编写ToDo应用程序时获得了[object Undefined]-,node.js,angularjs,mongodb,express,mongoose,Node.js,Angularjs,Mongodb,Express,Mongoose,嗨 我正在使用MEAN堆栈编写一个TODO应用程序。 我正在使用来自的轮询应用程序作为我的基础 我正在尝试实现两个基本操作:获取所有todo和删除todo项 我已经成功地完成了在MongoDB中存储数据的部分。我还成功地测试了与数据库的连接 但是,当我运行代码时,会出现以下错误: Error: .get() requires callback functions but got a [object Undefined] at C:\basestation\utopianSpace\ToD

我正在使用MEAN堆栈编写一个TODO应用程序。 我正在使用来自的轮询应用程序作为我的基础

我正在尝试实现两个基本操作:获取所有todo和删除todo项

我已经成功地完成了在MongoDB中存储数据的部分。我还成功地测试了与数据库的连接

但是,当我运行代码时,会出现以下错误:

Error: .get() requires callback functions but got a [object Undefined]
    at C:\basestation\utopianSpace\ToDo\node_modules\express\lib\router\index.js:252:11
    at Array.forEach (native)
    at Router.route (C:\basestation\utopianSpace\ToDo\node_modules\express\lib\router\index.js:248:13)
    at Router.(anonymous function) [as get] (C:\basestation\utopianSpace\ToDo\node_modules\express\lib\router\index.js:270:16)
    at Function.app.(anonymous function) [as get] (C:\basestation\utopianSpace\ToDo\node_modules\express\lib\application.js:414:26)
    at Object.<anonymous> (C:\basestation\utopianSpace\ToDo\app.js:31:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
index.js

var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://localhost/', 'tododb');

db.on('error', function () {
      console.log('Error! Database connection failed.');
    });
db.once('open', function (argument) {
      console.log('Database connection established!');
});

var ToDoSchema = require('./../models/todo.js').todoSchema;
var Todo = mongoose.model('todoSchema', ToDoSchema);

exports.index = function(req, res) {
    res.render('index', {
        title : 'Todo'
    });
};
todo.js

var mongoose = require('mongoose');
 var todoSchema_ = new mongoose.Schema({
    tname : 'String',
    tdate : 'String',
    tstatus : 'String'
});

 exports.todoSchema = todoSchema_;
node-app.js

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/todo', routes.todo);



http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
services.js

angular.module('todoServices', [ 'ngResource' ]).factory('ToDO',
        function($resource) {
            return $resource('todo', {}, {
                query : {
                    method : 'GET',

                    isArray : true
                }
            })
        })
routes.js

/**
 * Module dependencies.
 */

var utils = require('../utils');

/**
 * Expose `Route`.
 */

module.exports = Route;

/**
 * Initialize `Route` with the given HTTP `method`, `path`,
 * and an array of `callbacks` and `options`.
 *
 * Options:
 *
 *   - `sensitive`    enable case-sensitive routes
 *   - `strict`       enable strict matching for trailing slashes
 *
 * @param {String} method
 * @param {String} path
 * @param {Array} callbacks
 * @param {Object} options.
 * @api private
 */

function Route(method, path, callbacks, options) {
  options = options || {};
  this.path = path;
  this.method = method;
  this.callbacks = callbacks;
  this.regexp = utils.pathRegexp(path
    , this.keys = []
    , options.sensitive
    , options.strict);
}

/**
 * Check if this route matches `path`, if so
 * populate `.params`.
 *
 * @param {String} path
 * @return {Boolean}
 * @api private
 */

Route.prototype.match = function(path){
  var keys = this.keys
    , params = this.params = []
    , m = this.regexp.exec(path);

  if (!m) return false;

  for (var i = 1, len = m.length; i < len; ++i) {
    var key = keys[i - 1];

    var val = 'string' == typeof m[i]
      ? decodeURIComponent(m[i])
      : m[i];

    if (key) {
      params[key.name] = val;
    } else {
      params.push(val);
    }
  }

  return true;
};
道歉,因为您可能会发现多个错误

问候
abhi

您的路线代码在哪里?这就是错误所抱怨的部分。这个问题非常类似,甚至连行号都一样!确保您正在导出和引用正确的导出内容,以确保routes.todo在我看来不太正确
/**
 * Module dependencies.
 */

var utils = require('../utils');

/**
 * Expose `Route`.
 */

module.exports = Route;

/**
 * Initialize `Route` with the given HTTP `method`, `path`,
 * and an array of `callbacks` and `options`.
 *
 * Options:
 *
 *   - `sensitive`    enable case-sensitive routes
 *   - `strict`       enable strict matching for trailing slashes
 *
 * @param {String} method
 * @param {String} path
 * @param {Array} callbacks
 * @param {Object} options.
 * @api private
 */

function Route(method, path, callbacks, options) {
  options = options || {};
  this.path = path;
  this.method = method;
  this.callbacks = callbacks;
  this.regexp = utils.pathRegexp(path
    , this.keys = []
    , options.sensitive
    , options.strict);
}

/**
 * Check if this route matches `path`, if so
 * populate `.params`.
 *
 * @param {String} path
 * @return {Boolean}
 * @api private
 */

Route.prototype.match = function(path){
  var keys = this.keys
    , params = this.params = []
    , m = this.regexp.exec(path);

  if (!m) return false;

  for (var i = 1, len = m.length; i < len; ++i) {
    var key = keys[i - 1];

    var val = 'string' == typeof m[i]
      ? decodeURIComponent(m[i])
      : m[i];

    if (key) {
      params[key.name] = val;
    } else {
      params.push(val);
    }
  }

  return true;
};