javascript 如何运行 index.jade 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8778604/
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
How do I run a index.jade file?
提问by Xtreme
Trying to learn HTML5 and downloaded a test project https://github.com/amiklosi/Comicr. There is a folder named views with a index.jade which I suppose is the start page. What does it take to run that type of files? I can not open it directly in the browser.
尝试学习 HTML5 并下载了一个测试项目https://github.com/amiklosi/Comicr。有一个名为 views 的文件夹,其中包含一个 index.jade,我认为它是起始页。运行这种类型的文件需要什么?我无法直接在浏览器中打开它。
回答by kubetz
jadeis a HTML templating engine. All jade files need to be transformed in the HTML.
jade是一个 HTML 模板引擎。所有的玉文件都需要在 HTML 中进行转换。
You need to install to install jade by running
您需要通过运行安装来安装 jade
npm install jade
Also don't forget that you need to install other dependencie like express, nodemailer, etc (see requires in the source code).
另外不要忘记您需要安装其他依赖项,如 express、nodemailer 等(请参阅源代码中的requires )。
Then run the app using
然后使用运行应用程序
node app.js
And the application should by available on http://localhost/3000. All Jade templates will be correctly rendered and displayed as HTML.
该应用程序应该在http://localhost/3000上可用。所有 Jade 模板都将正确呈现并显示为 HTML。
回答by Fabián Heredia Montiel
You create a app.js file with the following contents.
您创建一个包含以下内容的 app.js 文件。
var express = require('express')
var app = module.exports = express.createServer();
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
});
app.get('/', function(){
res.render('index', {option: 'value'});
});