GJain
GJain

Reputation: 5093

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

$ROOT/app/server/modules/queries.js

But it does not work.

Can I do what I want????

Upvotes: 3

Views: 1793

Answers (1)

Morgan ARR Allen
Morgan ARR Allen

Reputation: 10678

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 = ...

Upvotes: 6

Related Questions