Jade 和 NodeJs,有什么好的教程吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5200175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:55:01  来源:igfitidea点击:

Jade and NodeJs, any good tutorials?

node.jspug

提问by Lalith

I have started working with NodeJs. First, I was just using it for providing simple REST api which has access to NOSQL databases. Now I also want to build html pages and use NodeJS to serve static files, as well as dynamic content using ExpressJs. Jade seems to be the templating library on ExpressJs so planning to use it. Are there any good resources so that I can learn jade. Also is it easy to write some big html pages using jade? I'd prefer some thing like php script tags etc embeded in html files as it is more convenient.

我已经开始使用 NodeJs。首先,我只是使用它来提供可以访问 NOSQL 数据库的简单 REST api。现在我还想构建 html 页面并使用 NodeJS 来提供静态文件,以及使用 ExpressJs 提供动态内容。Jade 似乎是 ExpressJs 上的模板库,所以打算使用它。有没有什么好的资源可以让我学玉。用jade写一些大的html页面也容易吗?我更喜欢像 php 脚本标签等嵌入在 html 文件中的东西,因为它更方便。

Please let me know what you think about it and any alternatives I should look into.

请让我知道您对此有何看法以及我应该研究的任何替代方案。

Thanks

谢谢

采纳答案by generalhenry

Jade is the default template engine, but it's not your only option see: http://expressjs.com/guide/using-template-engines.html

Jade 是默认的模板引擎,但它不是您唯一的选择,请参阅:http: //expressjs.com/guide/using-template-engines.html

It sounds like you want a template engine that's more like <h1><% variable %></h1>you should try EJS

听起来你想要一个更像是<h1><% variable %></h1>你应该尝试EJS的模板引擎

http://mustache.github.com/and https://github.com/jquery/jquery-tmplare also well supported in node.

http://mustache.github.com/https://github.com/jquery/jquery-tmplnode.js中也得到了很好的支持。

Also of note is weld which using 100% valid html for it's templates http://blog.nodejitsu.com/micro-templates-are-dead

另外值得注意的是焊缝,它的模板使用 100% 有效的 html http://blog.nodejitsu.com/micro-templates-are-dead

Personally I like Jade in combination with Stylus(same minimal markup applied to css)

我个人喜欢将 Jade 与Stylus结合使用(应用于 css 的最小标记相同)

回答by Francisco

There is also a great resource called Jade Template Syntax by example.

还有一个很好的资源叫做Jade Template Syntax by example

回答by Marcos Oliveira

There's a very complete tutorial here: http://dailyjs.com/2010/11/01/node-tutorial/.

这里有一个非常完整的教程:http: //dailyjs.com/2010/11/01/node-tutorial/

These posts are well written, step by step and with full source code available. I recommend.

这些帖子写得很好,一步一步地提供了完整的源代码。我建议。

回答by guiomie

To send static files easily, just use: res.sendfile('index.html');

要轻松发送静态文件,只需使用:res.sendfile('index.html');