Skip to content

Instantly share code, notes, and snippets.

Forked from eliOcs/apps.js
Created Jan 22, 2013
What would you like to do?
/*jslint node: true */
"use strict";
var express = require("express"),
consolidate = require("consolidate"),
Handlebars = require("handlebars"),
fs = require("fs");
var app = express();
// Configure the Handlebars engine
app.engine("html", consolidate.handlebars);
app.set("view engine", "html");
app.set("views", __dirname + "/views");
// Register partials
var partials = "./views/partials/";
fs.readdirSync(partials).forEach(function (file) {
var source = fs.readFileSync(partials + file, "utf8"),
partial = /(.+)\.html/.exec(file).pop();
Handlebars.registerPartial(partial, source);
// Define a route that renders the index view
app.get("/", function (req, res) {
res.render("index", {
hello: "Hello",
world: "World"
"name": "express-and-handlebars",
"version": "0.0.0",
"main": "app.js",
"dependencies": {
"express": "3.x",
"consolidate": "0.4.0",
"handlebars": "1.0.7"
<p>{{ hello }}</p>
{{> partial }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment