Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Advanced Express Web Application Development

You're reading from   Advanced Express Web Application Development For experienced JavaScript developers this book is all you need to build highly scalable, robust applications using Express. It takes you step by step through the development of a single page application so you learn empirically.

Arrow left icon
Product type Paperback
Published in Nov 2013
Publisher Packt
ISBN-13 9781783282494
Length 148 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrew Keig Andrew Keig
Author Profile Icon Andrew Keig
Andrew Keig
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Advanced Express Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Foundations 2. Building a Web API FREE CHAPTER 3. Templating 4. Real-time Communication 5. Security 6. Scaling 7. Production Index

Server-side templating


Up until now our Express server has only served JSON; let's install a couple of modules that will assist us in serving HTML.

consolidate.js is a template engine consolidation library that was created to map all of Node's popular templating engines to the Express convention for templating, allowing them to work within Express:

npm install consolidate --save

handlebars.js is an extension to the mustache templating language. Handlebars is a logic-less templating language that keeps view and code separated:

npm install handlebars --save

In order to be able to serve our handlebar templates, we will have to make some changes to our Express server. Let's change the default template engine to handlebars by setting the app.engine:

app.engine('html', cons.handlebars);

Now register html as our view file extension. If we did not set this, we would need to name our view index.hbs instead of index.html, with .hbs being the extension for handlebars templates.

app.set('view engine'...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime