Search code examples
javascriptnode.jsexpresshandlebars.jsassemble

How can I use handlebars-helpers library in express.js?


I use currently hbs as template engine in express.js. I think the handlebars-helpers library very useful.

But I have no idea how I can integrate this library. I also don't find a description for usage.

Thanks in advance.


Solution

  • First install it:

    $ npm i handlebars-helpers
    

    Next, add this to your Express app (probably before the template engine configuration):

    var Handlebars = require('hbs').handlebars;
    require('handlebars-helpers').register(Handlebars, {});
    

    This will only work if your app directory contains a package.json file (which may contain an empty object, {}, but is does have to exist).