Search code examples
node.jsexpresspug

Disable view cache for pug (jade) templates in express


I use "express": "^4.14.0", "pug": "^2.0.0-beta6"

app.set('view engine', 'jade');
...
app.get('/', function (req, res) {
    res.render('index.pug', {...});
}

When I use Express render function, it renders a template just once. If I change pug-template I'll get an old page version based on an already compiled template. For dev purposes, I need express recompiling .pug template for every render call. How can I achieve this?

I tried something like:

app.disable('view cache'); OR
app.set('view cache', false); OR
app.set('view cache', 'disabled');

But none of those were helpful.


Solution

  • Disappointing, but working:

    const pug = require('pug');
    const path = require('path');
    res.send(pug.renderFile(path.join(__dirname,'template.pug'), templateObj));