路由器怎么可能"未定义"在我的Node应用程序中?

时间:2014-09-26 19:10:45

标签: node.js express

var express = require('express')
var router = express.Router();

我正在调试我的节点应用并定义了express,但在踩过var router行后,router仍未定义,这怎么可能发生?

如果你必须,那么这里是所有代码:

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

var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

// New Code
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/sparks');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.engine('html', require('ejs').renderFile);
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')));
app.use(express.static(__dirname + '/fancy_scripts'));
app.use('/fancy_scripts',  express.static(__dirname + '/fancy_scripts'));


app.use(function(req,res,next){
    req.db = db;
    next();
});

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

//var router = express.Router();
//
///* GET home page. */
//router.get('/', routes.index);

如果要猜测app.use(app.router);

可能是罪魁祸首......?

0 个答案:

没有答案