disable EJS caching in production

2020-07-23 05:10发布

问题:

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!

回答1:

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');