I'm trying to just get a simple page running with node and handlebars, but the page doesn't render correctly. When I go to http://localhost:8080/ I just get raw HTML text in the browser. Here's my code:
main.js
var express = require('express');
var app = express();
var handlebars = require('express-handlebars').create({defaultLayout:'main'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('port', 8080);
app.get('/',function(req,res){
res.type('text/plain');
res.render('home');
});
app.listen(app.get('port'), function(){
console.log('Express started on http://localhost:' + app.get('port') + '; press Ctrl-C to terminate.');
});
home.handlebars
<h1>The Home Page</h1>
main.handlebars
<!doctype html>
<html>
<head>
<title>Demo Page</title>
</head>
<body>
}
</body>
</html>
I'm running this in NetBeans but even if I try doing it through the command line, the result is the same.
via Taylor Liss
No comments:
Post a Comment