我从NodeJS开始,但是我的代码有一个问题。我会给你看密码。
我需要用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;
}路线/主页.
module.exports = function(app){
var home = app.controllers.home;
app.get('/home',home.index);
}错误
npm start
> 4cash@0.0.1 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! 4cash@0.0.1 start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the 4cash@0.0.1 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模式加载我的应用程序。
发布于 2014-12-10 17:47:02
删除除了home.js之外的“路由”文件夹下的所有文件。我认为您有默认的索引和用户路由文件,这会造成这些问题。
可以从index.js和users.js文件中删除以下行以避免出现问题。
var express = require('express');
var router = express.Router();对不起我的英语。
https://stackoverflow.com/questions/25944668
复制相似问题