Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // book: "Express web application development" by Hage Yappa
- // app.js
- var http = require('http')
- var handlebars = require('express-handlebars').create({ defaultLayout: 'main' });
- var express = require('express');
- var app = express();
- app.engine('handlebars', handlebars.engine);
- app.set('view engine', 'handlebars');
- app.get('/', function(req, res) {
- res.render('index', {
- title: "Welcome"
- });
- });
- app.get('/hello', function(req, res) {
- res.render('hello', {
- title: "Hello"
- });
- });
- app.get('/test', function(req, res) {
- res.send("Some test");
- });
- http.createServer(app).listen(3000, function() {
- console.log("Express app started");
- });
- // ../views/layouts/main.handlebars
- <!doctype html>
- <html>
- <head>
- <title>{{ title }}</title>
- </head>
- <body>
- {{{ body }}}
- </body>
- </html>
- // ../views/index.handlebars
- Welcome!
- // ../views/hello.handlebars
- <b>Hello!</b>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement