1
我开始在NodeJS,但我的代码有问题。我会显示代码。尝试使用快速加载和表达4
我需要在MVC模式下加载应用程序,我使用的是express-load
,但在创建加载顺序时会出错。
app.js(最重要的部分)
var load = require('express-load');
...
load('models').then('controllers').then('routes').into(app);
控制器/ home.js
module.exports = function(app){
var HomeController = {
index: function(req,res) {
res.render('home/index');
}
}
return HomeController;
}
路由/ home.js
module.exports = function(app){
var home = app.controllers.home;
app.get('/home',home.index);
}
错误
npm start
> [email protected] start /Users/ewertonmelo/Documents/projects/4cash
> node ./bin/www
/Users/ewertonmelo/Documents/projects/4cash/node_modules/express/lib/router/index.js:120
var search = 1 + req.url.indexOf('?');
^
TypeError: Cannot call method 'indexOf' of undefined
at Function.proto.handle(/Users/ewertonmelo/Documents/projects/4cash/node_modules/express/lib/router/index.js:120:28)
at Object.router(/Users/ewertonmelo/Documents/projects/4cash/node_modules/express/lib/router/index.js:27:12)
at /Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/lib/express-load.js:232:17
at iterate (/Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/node_modules/async/lib/async.js:131:13)
at /Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/node_modules/async/lib/async.js:142:25
at /Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/lib/express-load.js:252:7
at iterate (/Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/node_modules/async/lib/async.js:131:13)
at /Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/node_modules/async/lib/async.js:142:25
at /Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load/lib/express-load.js:252:7
at iterate (/Users/ewertonmelo/Documents/projects/4cash/node_modules/express-load(/node_modules/async/lib/async.js:131:13)
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is most likely a problem with the 4cash package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls 4cash
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "start"
npm ERR! cwd /Users/ewertonmelo/Documents/projects/4cash
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/ewertonmelo/Documents/projects/4cash/npm-debug.log
npm ERR! not ok code 0
因为即使不使用模型,修改了load
load('controllers').then('routes').into(app);
控制器和路线存在,但给错误。 我想加载我的应用程序在MVC模式。