我試圖在快速應用中添加新路由,但在嘗試啓動服務器時出現錯誤。該錯誤是添加新路由到節點快車
C:\development\node\express_app\node_modules\express\lib\router\index.js:252
throw new Error(msg);
^
Error: .get() requires callback functions but got a [object Undefined]
這裏是我的文件,我是新來的節點,以便讓我知道如果我離開了一個重要文件,
路線/ furniture.js
exports.furniture = function(req, res){
res.render('furniture', { title: '4\267pli' });
};
路線/ index.js
/*
* GET home page.
*/
exports.index = function(req, res){
res.render('index', { title: '4\267pli' });
};
的意見/ furniture.ejs
<!DOCTYPE html>
<html>
<head>
<title>4·pli -- architecture</title>
<link rel='stylesheet' href='/stylesheets/style.css'/>
<link href='http://fonts.googleapis.com/css?family=Didact+Gothic' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="wrapper">
<h1 class="logo"><%= title %></h1>
</div>
</body>
</html>
app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, furniture = require('./routes/furniture')
, 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', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
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('/users', user.list);
app.get('/furniture', routes.furniture);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
感謝偉大工程 – 2013-05-14 17:13:29
@ 3boll什麼,如果你想有以下幾個用戶的功能。 .. index.js admin.js和foo.js ...你會怎麼寫? – Cmag 2013-12-02 01:59:02
@Clustermagnet檢查添加到響應中的代碼。 – jmingov 2013-12-02 19:08:32