require an external module in jade in a node.js webserver


I need to require a util module in my jade template to do some checking.

Can I do that? I tried following in a jade template which sits in $ROOT/views/jade/sample.jade

var utils = require('../../app/server/modules/queries.js')

for a module that sits in


But it does not work.

Can I do what I want????

Problem courtesy of:


You can register helpers from within Express.

In a request handler.

var utils = require('../../app/server/modules/queries.js')
function(req, res) {
  res.render("sample", {
    locals: {
      title: "Welcome to Derpco",
      someUtilFunction: utils.someUtilFunction

Also you can register helpers globally using app.locals.helpername = ...

Solution courtesy of: Morgan ARR Allen


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.