Our last Hello, World example
Now create a file lasthello.js
in the project folder. For convenience, we added the relevant code to the previous Express example. Everything that worked before still works but if you type http://localhost:3000/
, you will see a page with the layout from the layout file and {{{body}}}
replaced by(you guessed it):
var express = require('express'); var path = require('path'); var app = express(); var handlebars = require('express-handlebars') .create({ defaultLayout:'main' }); app.engine('handlebars', handlebars.engine); app.set('view engine', 'handlebars'); app.set('port', process.env.PORT || 3000); var options = { dotfiles: 'ignore', etag: false, extensions: ['htm', 'html'], index: false }; app.use(express.static(path.join(__dirname, 'public') , options )); app.get('/', function(req, res) { res.render('hello...