Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A synchronous, minimal render()-generating function for use with Express or Koa (or whatever)
const fs = require('fs')
const path = require('path')
const Handlebars = require('handlebars')
const generateHandlebarsTemplate =
templateSource => Handlebars.compile(templateSource);
module.exports = viewsPath => {
const files = fs.readdirSync(viewsPath)
const templates = {};
files.forEach(file => {
templates[path.basename(file, '.hbs')] =
fs.readFileSync(path.join(viewsPath, file), { encoding: 'utf8' })
return (name, data) => templates[name](data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment