没有模板引擎的 Node.js [英] Node.js without a template engine

查看:31
本文介绍了没有模板引擎的 Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Node.js 的新手,正在努力学习.据我所知,使用模板引擎(例如 Jade)是很常见的,即使是 CSS(例如 Stylus).老实说,我在那里看到的所有教程都涉及到布局的模板引擎.

I'm new into Node.js and trying to learn. From what I have understood it's common to use a template engine (eg. Jade), even for CSS (eg. Stylus). To be honest, all the tutorials I have seen out there involve a template engine when it comes to the layout.

问题是我不想使用模板引擎,因为我认为它不必要地复杂.

The thing is that I don't want to use a template engine because I think it's unnecessarily complex.

这里是一个指向 Node 样板的链接(不幸的是,它不适用于某些原因),但选项 1 不应为布局使用任何模板引擎.

Here is a link to a boilerplate for Node (unfortunately it doesn't work by some reason), but Option 1 shouldn't be using any template engine for the layout.

那么,将 Node.js 和 Mongodb 与普通"HTML(5) 结合的最简单方法是什么?例如,是否可以将 HMTL5 Boilerplate 与 Node 一起使用?

So, what is the easiest way to combine Node.js and Mongodb with "normal" HTML(5)? Is it possible for example to use HMTL5 Boilerplate with Node?

推荐答案

使用 express,您只需在响应中发送 html5:

Using express, you would just send the html5 in the response:

app.get('/', function(req, res){
  res.send('<header>Hello World</header>');
});

然而,我会说在大多数情况下模板引擎不会增加复杂性.如果您要呈现动态内容,则关注点分离会使事情变得更简单.

However, I would say that in most cases a templating engine doesn't add complexity. The separation of concerns makes things simpler if you are rendering dynamic content.

这篇关于没有模板引擎的 Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆