我尝试了从种子开始的这一简单更改,并创建了相应的.html文件(例如index.html)。
//app.set('view engine', 'jade');
app.set('view engine', 'html');
这个文件保持不变:
exports.index = function(req, res){
res.render('index');
};
但是在跑步的时候我得到了
500错误:找不到模块'html‘
我唯一的选择是使用'ejs‘吗?我的意图是将普通超文本标记语言与AngularJS结合使用。
发布于 2013-07-29 03:14:28
在另一个链接上的答案是有效的,但是为了服务于HTML,根本不需要使用视图引擎,除非你想设置时髦的路由。相反,只需使用静态中间件:
app.use(express.static(__dirname + '/public'));
发布于 2014-03-06 06:50:28
在您的服务器配置中尝试此选项
app.configure(function() {
app.use(express.static(__dirname + '/public')); // set the static files location
app.use(express.logger('dev')); // log every request to the console
app.use(express.bodyParser()); // pull information from html in POST
app.use(express.methodOverride()); // simulate DELETE and PUT
app.use(express.favicon(__dirname + '/public/img/favicon.ico'));
});
然后,路由的回调函数将如下所示:
function(req, res) {
res.sendfile('./public/index.html');
};
发布于 2016-09-06 20:47:11
没有视图引擎是必要的,如果你想使用angular与简单的纯html文件。下面是如何做的:在你的route.js
文件中:
router.get('/', (req, res) => {
res.sendFile('index.html', {
root: 'yourPathToIndexDirectory'
});
});
https://stackoverflow.com/questions/17911228
复制相似问题