注意:我的自动回复在帖子末尾
我正在尝试更好地体验 nodeJS,但我真的不喜欢将所有脚本放在一个文件中。
所以,按照这里的帖子我使用这个结构
./
config/
enviroment.js
routes.js
public/
css/
styles.css
images
views
index
index.jade
section
index.jade
layout.jade
app.js
我的文件现在是:
app.js
var express = require('express');
var app = module.exports = express.createServer();
require('./config/enviroment.js')(app, express);
require('./config/routes.js')(app);
app.listen(3000);
enviroment.js
module.exports = function(app, express) {
app.configure(function() {
app.use(express.logger());
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade'); //extension of views
});
//development configuration
app.configure('development', function() {
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
//production configuration
app.configure('production', function() {
app.use(express.errorHandler());
});
};
routes.js
module.exports = function(app) {
app.get(['/','/index', '/inicio'], function(req, res) {
res.render('index/index');
});
app.get('/test', function(req, res) {
//res.render('index/index');
});
};
layout.jade
!!! 5
html
head
link(rel='stylesheet', href='/css/style.css')
title Express + Jade
body
#main
h1 Content goes here
#container!= body
index/index.jade
h1 algoa
我得到的错误是:
错误:无法查找视图“索引/索引” 在 Function.render (c:\xampp\htdocs odejs 使用 ode_modules xpress\lib 应用程序.js:495:17) 在渲染时(c:\xampp\htdocs odejs 使用 ode_modules xpress\lib 响应.js:614:9) 在 ServerResponse.render (c:\xampp\htdocs odejs 使用 ode_modules xpress\lib 响应.js:638:5) 在 c:\xampp\htdocs odejs 使用