If we look at the node_modules/express/lib/view.js
, we find that the design of the template path all after the node_modules/express/lib/view.js
in the file name should be considered as an extension:
this.ext = extname(name); // 'view.sample' => '.sample' this.name = name; // 'view.sample' => 'view.sample'
And when we try to load the appropriate file extension mechanism, you will create an error:
if (!opts.engines[this.ext]) { // '.sample' engine not found // try load engine and throw error opts.engines[this.ext] = require(this.ext.substr(1)).__express; }
Ok, what to do? Just add the extension:
app.get('/sample', function(req, res){ res.render('view.sample.ejs'); })
source share