Search code examples
node.jsexpresspugtemplate-engineejs

disable EJS caching in production


It seems like whenever my process.NODE_ENV is set to production, EJS templating engine will cache all my .html files. So any modifications in those files will not be displayed, unless server restarts.

app.engine('.html', require('ejs').__express);

Is there a way to disable caching template on express? Thanks!


Solution

  • It seems like this is set explicitly as part of express's built-in code

    if (env === 'production') {
      this.enable('view cache');
    }
    

    This gets called by app.init which is called by createApplication which is the function that gets exported and what you probably are calling with app = express(). You can immediately disable the caching on your own:

    app = express();
    app.disable('view cache');