Saturday, 6 May 2017

Loading Server Side Rendered Templates in NodeJS

As a NodeJS developer who needs to render some HTML service side, I'm spoilt for choice when it comes to template languages -- mustache, handlebars, doT, Dust, EJS, etc. I could probably use a different template module every day of the month if I wanted.

However, as I research most of these template modules, I've found they all (seem to?) work with templates that are already loaded into Javascript as a string. For example, this is the hello world example from the EJS GitHub README -- your template goes in the str variable.

ejs.compile(str, options);
// => Function

ejs.render(str, options);

Is there a generally accepted way (i.e. "best practice") on how to store and load these sorts of templates in a server-side javascript application? (On disk loaded with the fs module? Something else?)

Bonus points: Is there a template module that has this functionality built in?



via Alan Storm

No comments:

Post a Comment