Search code examples
node.jsnunjucks

Requiring node.js libraries from nunjucks


Is there a way to require a node.js library from inside a nunjucks template?

Something similar to the following:

{% set strftime = require('strftime') %}

Solution

  • var env = nunjucks.configure([...
    ...
    env.addGlobal('require', function(lib) { 
        return require(lib);
    });