呈现基本的 HTML 视图?
问题描述:
我有一个基本的 node.js 应用程序,我正在尝试使用 Express 框架启动它.我有一个 views
文件夹,其中有一个 index.html
文件.但是我在加载网络浏览器时收到以下错误.
I have a basic node.js app that I am trying to get off the ground using Express framework. I have a views
folder where I have an index.html
file. But I receive the following error when loading the web browser.
错误:找不到模块html"
Error: Cannot find module 'html'
下面是我的代码.
var express = require('express');
var app = express.createServer();
app.use(express.staticProvider(__dirname + '/public'));
app.get('/', function(req, res) {
res.render('index.html');
});
app.listen(8080, '127.0.0.1')
我在这里遗漏了什么?
答
你可以让 jade 包含一个纯 HTML 页面:
You can have jade include a plain HTML page:
在视图/index.jade
in views/index.jade
include plain.html
在视图/plain.html
in views/plain.html
<!DOCTYPE html>
...
和 app.js 仍然可以渲染 jade:
and app.js can still just render jade:
res.render(index)