How to compile jade template file to get string?

I have a view logic in my jade template file. How can I pass model in to jade and get html for further sending by email ?

You can try the following:

var jade = require('jade'),
    fs = require('fs');

fs.readFile('template.jade', 'utf8', function (err, data) {
    if (err) throw err;
    console.log(data);
    var fn = jade.compile(data);
    var html = fn({name:'Oleg'});
    console.log(html);
});

Where template.jade is the path to your template. And it look like this:

!!!
html
  head
    title= 'Hello world'
  body
    p Hello #{name}!

So you pass your model as input of the fn() function, and the output of it will be the html.

<!DOCTYPE html><html><head><title>Hello world</title></head><body><p>Hello Oleg!</p></body></html>

Also you can catch the string from render callback (express example)

exports.test1 = function(req, res){
  res.render('test1', { title: 'test1' }, function(err, body) {
    console.log(body);
  });

  res.send('wooo');
};

test1.jade

div
  = title
p hello world!

The answers all work for loading the jade template and compiling it to HTML using locals. However if you are sending HTML emails you need to be aware that most clients strip out all CSS classes. Use Juice (or something like it) to apply all of the CSS classes inline.