Tag: 胡须

节点胡须渲染服务器端

我试图创build一个简单的应用程序来编译胡须模板到静态页面服务器端,这是我到目前为止: var view = { title: "Joe", calc: function () { return 2+4; } }; var mustache = require("mustache"); var template = require("./home.template"); var output = mustache.to_html(template, view); console.log(output); 而我的模板看起来像: {{title}} spend {{calc}} 任何build议是什么导致这个失败? 这里是完整的错误信息: home.template:1 } spend {{calc}} ^ module.js:437 var compiledWrapper = runInThisContext(wrapper, filename, true); ^ SyntaxError: Unexpected token { at Module._compile (module.js:437:25) […]

TypeError:尝试在Express JS中使用Mustache时,this.engine不是函数

作为我在NodeJS上尝试的第一件事,我构build了一个简单的应用程序,显示一个HTML页面,告诉访问者他们的IP地址。 这是它的样子 var express = require('express'); var app = express(); app.set('view engine', 'mu2'); app.get('/', function (req, res) { res.setHeader('Content-Type', 'text/html'); // Do I have to do this? I'm not sure. res.render('frontPage.html', { ip: req.ip }); res.send(); }); app.listen(8080, function() { console.log("Listening on port 8080"); }); 以下是/views/frontPage.html样子: <!DOCTYPE html> <html> <head> <title>Hello, World!</title> </head> <body> <h1>Hello, […]

带胡子模板的空白输出,connect&node.js

我刚刚进入这个完整的node.js业务,并喜欢它; 不过,我遇到了一个涉及connect / mustach的问题。 这是简单的一个页面应用程序的代码; 在这一点上,我真的只是想让应用程序使用我的小胡子模板,以便我可以从那里拿走它。 var connect = require("connect"), fs = require("fs"), mustache = require("mustache"); connect( connect.static(__dirname + '/public'), connect.bodyParser(), function(req, res){ var data = { variable: 'Some text that I'd like to see printed out. Should in the long run come from DB.' }, htmlFile = fs.createReadStream( __dirname + "/views/index.html", { encoding: "utf8" […]