javascript - Node 中的基本 html 引擎

标签 javascript node.js express

我想用 HTML 编写 HTML。不是什么奇特的方式。唯一很酷的是能够使用某种 include 语句来包含每个页面的页眉/导航/页脚。

我看过哈巴狗、ejs、 mustache 、双节棍等等。我讨厌所有这些东西。我只是想写 HTML..

什么是简单的 Node 模块来做到这一点?如何在我的主 app.js 中设置渲染引擎?我正在使用 express

最佳答案

您只需设置快速路由即可连接 html 页面。这是一个简单的例子:

var express = require('express');

// Create express app
var app = express();

// Route index page to an index html page
app.get('/', function(req, res){
  res.sendFile(__dirname  + '/path/to/views/index.html');
});

// Create server
app.listen(8080, function(){
    console.log('Ready on port 8080...');
});

顺便说一句,ejs 基本上是 html,但具有一些额外的功能。您完全可以在 ejs 页面中只编写 html,然后在熟悉了 ejs 功能后开始使用它。

关于javascript - Node 中的基本 html 引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36960280/

相关文章:

javascript - 如何使用 Google Places API Web 服务从地点详细信息请求中获取所有地点详细信息?

javascript - 检查数组中链接的单击是否有子菜单键值。 IF true 运行一些代码 ELSE 运行其他代码

node.js - Runscope – 如何通过 POST 请求发送 JSON 正文?

javascript - Express 4.x 路由器和 Angular 有问题吗?

node.js - 如何在MongoDB中按日期查询文档?

javascript - 这个 jQuery 元素的 innerHTML 语句有什么问题?

javascript - 构造函数 vs componentWillMount;什么是 componentWillMount 可以做而构造函数不能做的?

node.js - 在 sails.js 中过滤用户帖子数据

javascript - 如何使用expressJs将JS、CSS和其他服务器端实用程序包含到NodeJs中的HTML页面中?

javascript - 在 ssr 应用程序中单击时,react-router-dom <Link/> 会清除 {history,match,location} 属性